Home > Net >  I have a serial port communication are amateur, vb.net serialport question answered requests bosses
I have a serial port communication are amateur, vb.net serialport question answered requests bosses

Time:09-24

I have a serial port communication are amateur, question answered requests bosses, according to the communication protocol, need sent to the instrument serial command to: STX + "00541" + etx + + CR + LF "13", I will be the string
I will than strings contain control characters converted to hexadecimal ASCII said
02 30 30 to 35 34 31 20 20 20 03 31 33 0 d 0 a in serial assistants used in hexadecimal to send, instrument response success,
So the question comes, if I am in ASCII way how do you say?
I written in vb.net program, a serial port serialport controls used in the write () method sends a string is no response, is there something I need in the heart of the program than string into hexadecimal byte array, how to turn?

Bosses, please feel free to comment!

CodePudding user response:

The integer number, a string into a Byte [] methods:

BitConverter. GetByte (data or string); Here is the default Unicode string,

//gb2312 encoding is converted into a byte []
System. Text. Encoding. GetEncoding (936). GetBytes (" content ");

CodePudding user response:

Or ask, so I control serialport via a serial port communication, how to send a string of the 14 to equipment (4 control characters, the three blanks) STX + "00541" + "13" + CR + LF + etx,
No response code as follows, instrument through a serial port debug tool above, can enter the hexadecimal code communication:
Dim strSendStr string
StrSendStr=CRH (2) & amp; "00541" & amp;" 13 "& amp; VbCr & amp; VbLf
Serialport1. Write (strSendStr) 'sends a string

CodePudding user response:


Serialport1. Write (strSendStr), as a string haven't sent out, because the hair after I receive a variable with the bytes of send buffer area, found or 0, finish the whole operation procedure, is no exception, is this why? There are bosses know?

CodePudding user response:

refer to the second floor deng dachaoshan response:
or ask, so I control serialport via a serial port communication, how to send a string of the 14 to equipment (4 control characters, the three blanks) STX + "00541" + "13" + CR + LF + etx,
No response code as follows, instrument through a serial port debug tool above, can enter the hexadecimal code communication:
Dim strSendStr string
StrSendStr=CRH (2) & amp; "00541" & amp;" 13 "& amp; VbCr & amp; VbLf
Serialport1. Write (strSendStr) 'send string

The building Lord set the serialport properties?
Serial port assistant serial port Settings is 9600, 7, E, 1,

CodePudding user response:

Thank warm-hearted netizen, has been solved, it is wrong code port selection, it is no wonder that no error, also send not succeed
  • Related