I cannot receive any response using RS232 in VB.NET

N

Thread Starter

Neroboi

Here is my code. Sorry i'm only a newbie. ^_^

serialport.open
serialport.write("01")
serialport.write("03")
serialport.write("00")
serialport.write("21")
serialport.write("00")
serialport.write("01")
serialport.write("crc")
serialport.write("crc")
textbox.text = serialport.readexisting
serialport.close

Someone told me that I should make the whole command to a constant string to get a request data.

I tried it but there is no response either.

Can anyone tell me what is wrong on my code?
 
R

Rick Williams

I am a newbie also, maybe you are closing the port before info or string is read. vb has examples for waiting to get all of string.
 
Unfortunately you are a long way off the mark.

1.) You have got to set up the port - Port Number, Baud rate, start/stop bits, data bit, parity.

2.) You need to create a buffer and send the message down as one message. Not as individual packets.

3.) You are sending Ascii characters down the line and this is probably not correct. "01" is not 00000001.

4.) You need to work out the CRC - it is definitely not "crc"

So I think you should do some more research. Just google vb.net and serial port.

Here is a link to a tutorial it should help.
http://www.dreamincode.net/forums/showtopic37361.htm

Good luck
 
> 1.) You have got to set up the port - Port Number, Baud rate, start/stop bits, data bit, parity. <

1. I already done this.

> 2.) You need to create a buffer and >send the message down as one message. >Not as individual packets. <

2. Why do i need to create a buffer before sending the command/message? Sending a message as one. Is the crc value included here?

> 3.) You are sending Ascii characters >down the line and this is probably not >correct. "01" is not 00000001. <

3. Do you mean that I need to convert the command/message into a byte? Before sending the command to the serial port?

> 4.) You need to work out the CRC - it >is definitely not "crc" <

4. I get your point here.

Thanks for the link it is very useful.
 
The tutorial actually is great and should answer all you questions but just to add...

Point 2.) Basically you should assembly the message first in say a string and then you only need one serialport.write where you send the whole string down as one packet.

Each time you use serialport.write it is seen as an individual packet so in your code the receiving device only get one part of the message at a time. It is like making a telephone call and saying "Hello" and then hanging up, and then making another call and saying "Bob".

Point 3.) You will have to consult the protocol manual for the device you are communicating with. The bytes could be transmitted as Text or as Hex. Please see the example for the conversions.

Point 4.) The CRC should be calculate and added to the buffer or string before you use serialport.write. There is a formula for the CRC but you probably need to consult the protocol manual for the calculation as there are different methods.

The example is pretty thorough and is done so that the code can be used universally. I would suggest you copy the code into you application and use it directly. If not you could simply the port settings and displays but pay attention to the way the message is transmitted and received.

I hope this has helped you.

Good luck
 
Top