I am trying to write a function to call a C function in a library using ⎕NA
This is what I have at present:
Code: Select all
ns NAi2cWriteByteData so
⍝ int i2cWriteByteData(unsigned handle,unsigned i2cReg,unsigned bVal)
⍝ This writes a single byte to the specified register of the device associated with handle.
⍝ handle:>=0,as returned by a call to i2cOpen
⍝ i2cReg:0-255,the register to write
⍝ bVal:0-0xFF,the value to write
⍝ Returns 0 if OK
ns.⎕NA'I ',so,'|i2cWriteByteData U U1 U1'
My problem is with the "unsigned bVal" which I have coded as "U1".
My code works when the value of bVal is between 0-127, but values between 128 and 255 are rejected by the C code at run time.
EG A bVal of 129 reports "bad bVal (-127)"
(Looks like a 2 compliment problem.)
Should I change the way I define bVal in the ⎕NA call, or how I assign values into bVal at run time?
Any suggestions?