Home > other >  C # PC serial port communication
C # PC serial port communication

Time:09-22

Compiled in c # PC serial port communication, since 232 is full duplex, so can open two line cheng send read data respectively,
So if you are going to adopt the way of "question and answer" to communicate, use which way is better?
1, the simulation of the modbus pattern, add the CRC check code, such as PC sends the query command, the c # to receive data continuously, at the same time, CRC check requirements will send instructions on to the next step, to accept a long time, see error,
2, use ASCII format, add "\ n" after each instruction, readline () think send to receive instruction at a time, if the command unrecognized, think error,
3, other ways to share the bai!

CodePudding user response:

Then cycle in a thread to read data (reads), through setting instruction button to send (write), through the lock to lock function to send and receive data, but occasionally will appear "button to send, receive information loop reads" this how to return a responsibility?

CodePudding user response:

Receive better overtime,

CodePudding user response:

refer to the original poster horse_2007s response:
in the preparation of c # PC serial port communication, since 232 is full duplex, so can open two line cheng send read data respectively,
So if you are going to adopt the way of "question and answer" to communicate, use which way is better?
1, the simulation of the modbus pattern, add the CRC check code, such as PC sends the query command, the c # to receive data continuously, at the same time, CRC check requirements will send instructions on to the next step, to accept a long time, see error,
2, use ASCII format, add "\ n" after each instruction, readline () think send to receive instruction at a time, if the command unrecognized, think error,
3, other ways to share the bai!

Use which kinds of means is a kind, but the problem is you want to ask one answer, no need to open two threads, opened is useless, because you have to wait to answer, so you still a thread is better, and all other communications will be a timeout threads, otherwise how to jump out of the waiting for you?
  • Related