Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

Java
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 :
Java
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");
	}
}
Posted
Updated 20-Jan-18 0:37am
v5
Comments
Richard MacCutchan 19-Jan-18 3:26am    
Just change you code to query the device after you have written the string, and check for response data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900