You are not logged in.
Hi,
I have upgrade from version 2.50.1 to 2.50.4 (upgraded the rapsberry PI image and software and RexDraw). I have a working c file to handle communcation with ph and orp probes. Since the upgrade I am unable to communicate with them (I get a 310 error code when trying to use the I2C function which I thinks maps to WriteRead).
I can't use the write or read function as there is no variable for the i2c address. If I use the I2C function and need to perform read only or write only I have to set the count to 0 so I can't turn on debug (I was hoping that this would be resolved in 2.50.4 as it happens to do one way read or write with I2C).
So I have tried to find a solution but can't. It was fully working for long time before the upgrade. I can also use my python script to read the pH or ORP values from the shell directly so the probes are working correctly.
My next step will be to use the logic analyzer to see if something is being sent from Rex but I am really sure nothing's been sent.
Here is a copy of the .c file. The problem happens when doing the read or write (init seem to be ok).
Thanks,
Fred
/************************************************************
*
* REXLANG - Reading data from MCP3422 AD converter via I2C
*
*************************************************************/
// 2017-04-30
#define I2CDEV_FNAME 67 // I2C device is defined by the fname parameter of the REXLANG block (e.g. set it to /dev/i2c-1 on the Raspberry Pi minicomputer)
long input(0) ph_request;
long input(1) ph_read;
long input(2) orp_request;
long input(3) orp_read;
double output(0) ph_value;
double output(1) orp_value;
long output(2) phw_status;
long output(3) phr_status;
long output(4) orpw_status;
long output(5) orpr_status;
//declaration of variables
long i2c_bufTx[3]; //buffer for transmitting data
long i2c_bufRx[7]; //buffer for receiving data
long i2c_bus_handle;
long i2c_chip_address;
long i2c_write_count;
long i2c_read_count;
long i2c_ret_fun;
//the init procedure is executed once when the REXLANG function block initializes
int init(void)
{
i2c_bus_handle = OpenI2C("/dev/i2c-1"); // open I2C bus
return 0;
}
//the main procedure is executed once in each sampling period
long main(void)
{
if (ph_read==1)
{
i2c_chip_address = 0x63; // 7-bit address of ph sensor
i2c_write_count = 0;
i2c_read_count = 7;
phr_status = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);
if ( i2c_bufRx[0] == 0x01 )
{
// [0] 0x01 Means value is ready to be read something else is ignored
// [1] 0x30 is 0, 0x31=1, 0x32=2, 0x33=3
// [2] 0x2E dot
// [3] first digit after dot
// [5] always 0 for end
//ph_value= ( (i2c_bufRx[1] - 0x30) + ((i2c_bufRx[3] - 0x30)*0.1) + ((i2c_bufRx[4] - 0x30)*0.0 1) );
ph_value=(i2c_bufRx[1] - 0x30) + ((i2c_bufRx[3] - 0x30)*0.1) + ((i2c_bufRx[4] - 0x30)*0.01);
}
}
if (orp_read==1)
{
i2c_chip_address = 0x62; // 7-bit address of ph sensor
i2c_write_count = 0;
i2c_read_count = 7;
orpr_status = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);
if ( i2c_bufRx[0] == 0x01 )
{
// [0] 0x01 Means value is ready to be read something else is ignored
// [1] 0x30 is 0, 0x31=1, 0x32=2, 0x33=3
// [2] 0x30 is 0, 0x31=1, 0x32=2, 0x33=3
// [3] 0x30 is 0, 0x31=1, 0x32=2, 0x33=3
// [4] 0x2E dot
// [5] first digit after dot
// [6] always 0 for end
//ph_value= ( (i2c_bufRx[1] - 0x30) + ((i2c_bufRx[3] - 0x30)*0.1) + ((i2c_bufRx[4] - 0x30)*0.0 1) );
orp_value=((i2c_bufRx[1] - 0x30)*100) + ((i2c_bufRx[2] - 0x30)*10) + (i2c_bufRx[3] - 0x30);
}
}
if (ph_request==1)
{
i2c_chip_address = 0x63; // 7-bit address of ph sensor
i2c_bufTx[0] = 0x52; // Send R command
i2c_bufTx[1] = 0x00;
i2c_write_count = 2;
i2c_read_count = 0;
phw_status = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);
}
if (orp_request==1)
{
i2c_chip_address = 0x62; // 7-bit address of ph sensor
i2c_bufTx[0] = 0x52; // Send R command
i2c_bufTx[1] = 0x00;
i2c_write_count = 2;
i2c_read_count = 0;
orpw_status = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);
}
return 0;
}
//the exit procedure is executed once when the task is correctly terminated
// (system shutdown, downloading new control algorithm, etc.)
long exit(void)
{
if(i2c_bus_handle>=0) Close(i2c_bus_handle); // close I2C bus
return 0;
}
Offline
I have checked with the logic analyzer and there is nothing going on the i2c bus from rex. So must be something with the function giving an exception even before trying to use the i2c bus.
root@raspberrypi:~/Raspberry-Pi-sample-code# i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- 18 -- -- 1b -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- 62 63 -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77
root@raspberrypi:~/Raspberry-Pi-sample-code#
Offline
Hi Fred,
I'm sorry to hear you are struggling with upgrade to 2.50.4. I do not see any problem in your code. I'll have a closer look at this issue and I hope to give you some hints tomorrow. If you could provide the following information, that would be great:
What OS image are you using? Raspbian with PIXEL, Raspbian Lite, etc.?
Did you run "apt upgrade" after flashing the SD card?
Can you please provide links to the pH and ORP probes?
Can you please upload the whole project (*.mdl, *.c)?
Best regards,
Jaroslav
Monarco HAT for Raspberry Pi - Lightweight I/O for monitoring, archiving and control.
Raspberry Pi in industrial automation!
Offline
Hi Fred,
our developers have tracked down the root cause of this bug. We'll prepare a hotfix for that. Until then, the only workaround is to stick to version 2.50.1. Sorry for the troubles and thanks for reporting the problem!
Best regards,
Jaroslav
Monarco HAT for Raspberry Pi - Lightweight I/O for monitoring, archiving and control.
Raspberry Pi in industrial automation!
Offline