Data conversions: handling signed/unsigned integers in the PLC-5 and SLC 500
In the SLC 500 and PLC-5 processors, integer values are stored as signed integers with a range of -32,767 through +32,767. When reading integer file data (
N
file type) into Microsoft Excel, the integer data appears as an unsigned integer with a range of 0 through 65536. If you want the integer data to appear as a signed integer, write a formula or macro to convert the data. Following are examples of the conversion for a hot link and a cold link.For a hot link, you could use a formula to convert the data. For example, if cell
B1
on a worksheet contains a hot link to an integer value in a PLC-5 that you want to convert to a signed integer, use this formula: =IF(B1>32768,B1-65536,B1)
. Place the formula in cell B2
or wherever you wish the signed data to appear.For a cold link, you could use the following macro to convert the data:
=INITIATE("rslinx","testsol") requests a DDE channel to RSLinx Classic (rslinx), topic testsol. It returns a DDE channel number. |
=SET.NAME("read1",REQUEST(A1,"N7:25")) requests the data from N7:25 and assigns it to the name "read1". |
=IF(read1>32768) tests the data that was read to see if it should be signed or not. |
=SET.NAME("sign1",read1-65536) if the test is true the data is converted to a signed value. |
=FORMULA(sign1,"twoscomp.XLS!R7C3") places the data on a worksheet named TWOSCOMP.XLS. |
=ELSE() is executed if the data fails the IF test. |
=FORMULA(read1,"twoscomp.XLS!R7C3") places the read data on the worksheet TWOSCOMP.XLS. |
=END.IF() ends the IF test. |
=TERMINATE (A1) closes the DDE channel that was previously opened with the INITIATE command. |
=RETURN() ends the currently running macro. |
Provide Feedback