MODBUS Communication Problems

S

Thread Starter

srinivas duddu

Hi!! I have a problem , i request all of your help!! My VBCode doesnt work! I need to communicate to a Gas Analyser which supports MODBUS RTU. The instrument works with MODTEST utility of M/s Daniel Europe. Not with my VB code. with modtest software my query was 010300000001840A and the response from the device was 01030203BFF904 Find below the code sample i was working on In the MSComm Control i left the settings as commport:1 settings:9600,n,8,1 Handshaking: ComNone InBufferSize:1024 OutBufferSize:512 InputLength:7 DTR enable =TRue Private Sub CmdQuery_Click() MSComm1.Break = True MSComm1.CommPort = 1 MSComm1.PortOpen = True MSComm1.Output = "010300000001840A" MSComm1.InputMode = comInputModeText TxtResponse.Text = MSComm1.Input End Sub Using the Daniel Modtest utility i got the following response string from the analyser 01,03,02,03,BF,F9,04. bUT THERE is no response from the analyser. please help. please give your Email ID also . I feel some problem is with the code, please advice / suggest any remedy in this regards by srinivas
 
A
You need to create your Modbus command as an array of U8 bytes. Then convert this to an ASCII string before sending it to the serial port buffer. It appears you are sending a string of numbers to the Modbus device and it doesn't know what to do with this improperly formatted message. Modbus devices only understand arrays of U8 bytes as commands. I don't do Visual Basic so I can't help you out with how to do this in your language. Also, apparently you haven't tried spying on the comm port to see what you are actually shipping to the serial buffer. This was recommended in an earlier post. All your questions will immediately answer themselves if you could see exactly what you are sending.
 
R

Ravichandran R

Hi Srinivas,

Try with the following.
MSComm1.Output = chr(&H01) & chr(&H03) & chr(&H00)& chr(&H00) & chr(&H00) & chr(&H01) & chr(&H84) & chr(&H0A)

Keep the following statements in different cmd button. remove from query button.

MSComm1.InputMode = comInputModeText
TxtResponse.Text = MSComm1.Input

Ravichandran R
[email protected]
 
1.make sure you receive in textmode mscomm1 property.
2.check and make sure mscomm1.RThreshold is not 0 if it is you will never fire the ccomEvReceive
event if you are dealing with fixed length string you can set this to the string lenth.

in private sub form_load
mscomm1.RThreshold = (String length) example 32
mscomm1.settings = "19200,n,8,1
mscomm1.commport = 1
mscomm1.portopen = true

end sub
private sub mscomm1_oncomm()
dim Sdata as string 'string to hold data
dim pdata as string ' string to use for parsing Sdata
if mscomm1.CommEvent =comEvReceive then

Sdata = mscomm1.input
pdata = mid$(Sdata,1,15)' this will grab text data starting a postion 1 in string up to postion 15
txtText1 = pdata


the Xmit is

txtText2 = a645789201 ' command example to send
cmd btn click event
mscomm1.output = txtText2

this information and more like it can be found at
http://www.rentron.com
a great site with great people ask for
bruce and tell him Chas sent you tel (719)269-3469
 
Top