DISABLE ADBLOCK

ADBlock is blocking some content on the site

ADBlock errore

Question

I am not able to write a string on to my Arduino using Visual C++. I am somehow able to open the COM port but not able to send data to the Arduino. What would the problem actually be in my case?

int main()
{
    HANDLE hComm;
    hComm = CreateFileA("\\\\.\\COM11",
            GENERIC_READ | GENERIC_WRITE,
            0,
            0,
            OPEN_EXISTING,
            FILE_FLAG_OVERLAPPED,
            0);

    if (hComm == INVALID_HANDLE_VALUE)
    {
        printf("com not opened");
    }
    else
    {
        printf("COM OPENED");
    }

    COMMTIMEOUTS cto = { 1, 100, 1000, 0, 0 };
    DCB dcb;
    memset(&dcb,0,sizeof(dcb));
    dcb.DCBlength = sizeof(dcb);
    dcb.BaudRate = 38400;
    dcb.fBinary = 1;
    dcb.Parity = NOPARITY;
    dcb.StopBits = ONESTOPBIT;
    dcb.ByteSize = 8;

    if(!SetCommState(hComm,&dcb))
    {
        printf("HI");
    }

    while(1)
    {
        char bag[]="L";
        DWORD read=0 ;
        DWORD write=1; // Number of bytes to write to serial port
        //         Decmial value to write to serial port
        WriteFile(hComm, bag,write,&write, NULL);
    }
}

No correct solution

OTHER TIPS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow