One shot modbus write

More
1 month 3 days ago #76 by jds
Replied by jds on topic One shot modbus write
For what it's worth: the code I use now to fetch the status from the modbus slave and module to check afterwards if my communication is OK. Smaal notice, I use a TCP/RTU convertor so I have to check both statussen, one for the TCP connection, one for the RS485 connection.
The code is probably subject for improvement, so advice is always welcome.
Code:
classdef Da1 BaseFcXylem; static pwr_tStatus sts = 0; static pwr_tStatus *status1 = 0; static pwr_tStatus *status2= 0; if (sts == 0 && status1 == 0 && status2 == 0) { pwr_tAName aname1; pwr_tAName aname2; char *s; pwr_tAttrRef aref; // Get name of a channel and replace the channel with SendOp sts = gdh_AttrrefToName( &Da1->ErrorWordSW.SigChanCon, aname1, sizeof(aname1), cdh_mName_volumeStrict); if (ODD(sts) ){ s = strrchr(aname1, '-');  // or '-' if channel is child if (s)  *s = 0; strcpy(aname2,aname1); strcat(aname1, ".Status"); s = strrchr(aname2, '-');  if (s)  *s = 0; strcat(aname2, ".Status"); sts = gdh_NameToAttrref(pwr_cNObjid, aname1, &aref); if (ODD(sts)) sts = gdh_AttrRefToPointer(&aref, (void **)&status1); sts = gdh_NameToAttrref(pwr_cNObjid, aname2, &aref); if (ODD(sts)) sts = gdh_AttrRefToPointer(&aref, (void **)&status2); } } if (status1 && status2 && ODD(sts)){ OI1 = (int) *status1; // status module OI2 = (int) *status2; // status slave }

Please Log in or Create an account to join the conversation.

Time to create page: 0.423 seconds
Powered by Kunena Forum