raining010 Posted September 21, 2013 Share Posted September 21, 2013 Hi, I'm testing program, and there is an alert: C1086 One of the parameters was empty: Word_Merge Line 4 - Uncaught error in sequence Word_Merge in my sequence, the content of line 36 is: If (V.ABSS[0]==1) I define this sequence as a function, more codes are like below: function Word_Merge() If (V.ABSS[0] == 1) SetBit(CANOPENER1_40500[0],16) V.CC_START[0] = 0 Endif I don't where I am wrong, thanks Link to comment Share on other sites More sharing options...
AzeoTech Posted September 22, 2013 Share Posted September 22, 2013 I can't say since you didn't post the contents of Word_merge around line 4. I will say this: SetBit(x, 16) doesn't set the 16th bit of x, but rather returns the result of setting the 16th bit of x. In other words, this line: SetBit(CANOPENER1_40500[0],16) does nothing. Instead you need: CANOPENER1_40500 = SetBit(CANOPENER1_40500[0],16) assuming of course that CANOPENER1_40500 is not a channel, since you can't assign values to channels like that. Link to comment Share on other sites More sharing options...
raining010 Posted September 22, 2013 Author Share Posted September 22, 2013 hi, thanks for your quick reply. But I have a demand now, want to set/reset a bit of the channel(its I/O type : set register S16(6)). I need the grammar of this code, then I would write a function to be called by many buttons. Thanks in advance! Link to comment Share on other sites More sharing options...
AzeoTech Posted September 22, 2013 Share Posted September 22, 2013 First, are you sure your device doesn't support Modbus coils? This would be the correct place to put bit settings. Some devices will replicate coils into the holding register space because some Modbus master's can't do coils. If your device does support coils for these registers, use them because they'll take care of everything for you. If you are stuck with bits, you are going to have to keep track of the current state somehow, perhaps by reading the register. Let's say you have an input channel called ch_in, and an equivilent output channel for the same register called ch_out. The function might be something like: function setCoil(string chName, bit) execute(chName + "_out = setBit(" + chName + "_in, bit)") and: function resetCoil(string chName, bit) execute(chName + "_out = clearBit(" + chName + "_in, bit)") Then to set the 13th bit, you'd just do for ch_out you'd do: setCoil("ch", 12) Then, as long as you name your channels with _in and _out at the end, it will work. Note that you can, technically, create a single read holding channel and actually set a value to it, thus eliminating the need for two channels, but I actually prefer separating them, as it helps me ensure that things are being set. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.