I am sending data through UART and whenever I am clicking the button I am receiving it in an android application text box using serial port communication.
problem:
How to read the values without the use of a button, directly it has to read the values in the textbox without the use of a button.
data I am sending through UART is a string.
What I have tried:
I have tried it with the use of a button and its working
Android application code to read value in text box:
Button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
{
data = "GETCR01";
if (usbService != null)
{
usbService.write(data.getBytes());
}
}
}
});
if (data == "GETCR01") {
switch (msg.what) {
case UsbService.MESSAGE_FROM_SERIAL_PORT:
String usb = (String) msg.obj;
mActivity.get().textView1.append(usb);
}
}
UART code :
void ConstructGPRSPkt(void) {
char iADC[20],rx_buff[256];
float vNum,conRes;
memset(iADC, 0x00, sizeof(iADC));
memset(rx_buff, 0x00, sizeof (rx_buff));
uart_io_gets(rx_buff, 256);
if (strstr(rx_buff, "GETCR01") != NULL)
{
vNum = (hApp.adc_ch.ADC_CH0_VAL + (ADC_CORR * hApp.adc_ch.ADC_CH0_VAL));
if (vNum < 0)
vNum = vNum * (-1);
ftoa(vNum, iADC, 3);
conRes=(vNum/CURR);
ftoa(conRes, iADC,3);
uart_io_puts(DC_PORT_UART, iADC);
uart_io_puts(DC_PORT_UART, "\r\n");
}
}