Hi Peter,
thank you for the suggestions.
I managed to send some bytes over the line (it seems - the send function returns the number of bytes sent), but I got an error while read:
hm2/hm2_7i76e.0: error finishing read! iter=6
I have read-request, read, write functions added to the servo thread (however, I am not sure about the order of the functions)
addf hm2_7i76e.0.read servo-thread
addf hm2_7i76e.0.read-request servo-thread
addf hm2_7i76e.0.write servo-thread
My realtime component is named dcell_ascii_test. I run the receive function in a thread with 2s period (to be able to track the rtapi_print_msg - which might not be very clever)
loadrt dcell_ascii_test names="hm2_7i76e.0.pktuart.0"
loadrt threads name1=test1 period1=2000000000
addf hm2_7i76e.0.pktuart.0.receive test1
What I am intending to do inside the hm2_7i76e.0.pktuart.0.receive function is to send a frame of 11B - "!001:SOUT?\r" like this:
rtapi_u16 message_length = 11;
rtapi_u16 message_size[1]={message_length,};
rtapi_u8 num_frames = 1;
unsigned char message[1*11] ={
//! 0 0 1 : S O U T ? \r
0x21, 0x30, 0x30, 0x31, 0x3a, 0x53, 0x4f, 0x55, 0x54, 0x3f, 0x0d
};
retval=hm2_pktuart_send(name, message, &num_frames, message_size);
rtapi_print_msg(0, "PktUART send: sent %d bytes\n", retval);
The slave device should then respond with some bytes of data I want to get:
rtapi_u8 num_frames = 1;
rtapi_u16 max_frame_length = 26;
unsigned char Replyd3[num_frames*max_frame_length];
rtapi_u16 frame_sizes3[26];
rxbytes=hm2_pktuart_read(name, Replyd3, &num_frames, &max_frame_length, frame_sizes3);
rtapi_print_msg(RTAPI_MSG_INFO, "PktUART receive: got %d bytes, %d frames\n", rxbytes, num_frames);
Do you have any idea why I get the error?
hm2/hm2_7i76e.0: error finishing read! iter=6
I am not sure if I can do all this inside the hm2_7i76e.0.pktuart.0.receive function (send a request and expect a response).
I think I should aswell set the line to transmit mode when transmitting and to receive mode when reading. But to be honest, I don't know how to work with the transmit enable pin.
Thank you.