dholden Posted October 2, 2017 Share Posted October 2, 2017 I have a variable (P4100) that I need to read the bits of and assign to variables. I was thinking it would work like this: //Digital Inputs PTR Input01->P4100.0.0; PTR Input02->P4100.0.1; PTR Input03->P4100.0.2; PTR Input04->P4100.0.3; However clearly this is not the correct approach, how would one do this correctly. By the way the Inputs are read from a ModbusTCP variable into the local P-Variables like so: cmd"ModbusRegisterRead 0,0,4,P4100" Which is why i am not simply addressing the corresponding I/O card Addresses. Link to comment Share on other sites More sharing options...
curtwilson Posted October 3, 2017 Share Posted October 3, 2017 PMAC P-variables are floating-point variables, so the locations of individual bit values "float" (are not fixed), and you cannot assign pointer variables to individual bits. First, you will want to define fixed-point M-variables to user buffer registers. For example: M4100->u.user:4096; // Sys.udata[1024] M4101->u.user:4100; // Sys.udata[1025] M4102->u.user:4104; // Sys.udata[1026] M4103->u.user:4108; // Sys.udata[1027] Then you can use: cmd"ModbusRegisterRead 0,0,4,M4100" Now, you can define other M-variables to individual bits of these fixed-point registers. ptr Input01->u.user:4096.0.1; // Bit 0 of Sys.udata[1024] ptr Input02->u.user:4096.1.1; // Bit 1 of Sys.udata[1024] ptr Input03->u.user:4096.2.1; // Bit 2 of Sys.udata[1024] ptr Input04->u.user:4096.3.1; // Bit 3 of Sys.udata[1024] Note that the starting bit number comes before the bit width in these definitions. Link to comment Share on other sites More sharing options...
dholden Posted October 3, 2017 Author Share Posted October 3, 2017 A couple of questions, First, why did you choose u.user:4096 as your starting point? Second how would you do the same thing (get a bit from an value) for: Sys.ModbusServerBuffer[0] Link to comment Share on other sites More sharing options...
curtwilson Posted October 3, 2017 Share Posted October 3, 2017 "Why did you choose u.user:4096 as your starting point?" No particular reason. I just did not want to imply that you had to start at offset 0, and many people use lower locations for other purposes. Registers in the user buffer can have M-variable pointers assigned easily to individual bits. This provided the closest working alternative to what you provided. Link to comment Share on other sites More sharing options...
Recommended Posts