Sign in to follow this  
mmartinezb

Problem Modbus Serial

Recommended Posts

I need to read function 07 (Read Exception status), of the Modbus serial, tries with all the functions by defect, but it is not possible.

Please help

Mauricio

Share this post


Link to post
Share on other sites

We do not currently support that function. However, you can probably generate the command directly. If your device ID is 1, then the command is simply:

0107\xE2\x41

assuming I got the CRC right. You can generate this command from script:

private string datain
// lock port so regular driver doesn't interfere
if (device.mydevice.lockport())
   try
	  // clear buffer
	  device.mydevice.purge()
	  // write output string
	  device.mydevice.write(chra({1,7,0xE2,0x41}))
	  // read 5 char response
	  datain = device.mydevice.read(5) 
	  // confirm valid response
	  if (mid(datain,1,1) == chr(7)) 
		 // put result into channel
		 MyChan.AddValue(asc(mid(datain,2,1))) 
	  endif
   catch()
   endcatch
   // release port
   device.mydevice.unlockport()
endif

I couldn't test this. Post if you have problems.

Share this post


Link to post
Share on other sites

it is necessary to create a new protocol ?

Quick -> Device configuration -> my device -> NEW PROTOCOL?

you can help me I am starting off with DACFActory.

Thank you very much

Mauricio

Share this post


Link to post
Share on other sites

No, you can use the same modbus device, and simply put the script I provided into a sequence and start it up whenever you want to run the query.

You could, technically, create your own protocol, but the only advantage would be easy reuse, and I suppose that you could create your own I/O type to do this query.

Share this post


Link to post
Share on other sites

Ok thank you very much by the information, already I could read function 7:

RGAM_42_MODBUS = my device

1 = address instrument

7= Funtion read exception status

0X2A and 0X30 =address of the required register

0x00 and 0x01 = number of the register to read

0x7D,0xDD = CRC Checksum (SimplyModbus6.3.2 it calculates the CRC very well )

Mydata = my chanel

CODE

private string datain
// lock port so regular driver doesn't interfere
if (device.RGAM_42_MODBUS.lockport())
   try
	  // clear buffer
	  device.RGAM_42_MODBUS.purge()
	  // write output string
	  device.RGAM_42_MODBUS.write(chra({1,7,0x2A,0x30,0x00,0x01,0x7D,0xDD}))

	  // read 5 char response
	  datain = device.RGAM_42_MODBUS.read(5) 
	  // confirm valid response
	  if (mid(datain,1,1) == chr(7)) 
		 // put result into channel
		Mydata.AddValue(asc(mid(datain,2,1))) 
	  endif

   catch()
   endcatch

endif

I use comm monitor of DAQFactory

TX: \x01\x07\x2A\x30\x00\x01\x07\xDD

"read(5) "

"Mydata.AddValue(asc(mid(datain,2,1))) "

RX: \x01\x07\x91\xE3\x9C

Thank you very much

Mauricio

Share this post


Link to post
Share on other sites

Glad it worked. Please see the end of this post for CRC calcs. I will be posting a CRC solution shortly.

Share this post


Link to post
Share on other sites

An important point, is necessary to add

device.RGAM_42_Modbus.UnlockPort()

For the continuous reading of the registries, it modifies the "If" by an "While" and device.RGAM_42_Modbus.UnlockPort()

private string datain
// lock port so regular driver doesn't interfere
While (device.RGAM_42_MODBUS.lockport())
   try
	  // clear buffer
	  device.RGAM_42_MODBUS.purge()
	  // write output string
	  device.RGAM_42_MODBUS.write(chra({1,7,0x2A,0x30,0x00,0x01,0x7D,0xDD}))

	  // read 5 char response
	  datain = device.RGAM_42_MODBUS.read(5) 
	  // confirm valid response
	  if (mid(datain,1,1) == chr(7)) 
		 // put result into channel
		Mydata.AddValue(asc(mid(datain,2,1))) 
	  endif
	   device.RGAM_42_Modbus.UnlockPort()
   catch()
   endcatch


endwhile

A new question, as I can transform this result to binary?

Thank you very much

Mauricio

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this