WriteFile() is Crashing my PC

Hi
I am trying to send approx 80Kbytes of data out the serial port COM2 using WriteFile.

I have used writefile many times for sending only a few hundred bytes, but never a file this big.

The PC locks up completely. I cannot even use "ctl,alt,del" it just beeps.

Presently i send 10 bytes out with Writefile and then " Sleep(35); "
The 10x bytes only take 10msec to TX so the sleep for 35ms is to allow them out the com buffers.

I then purge the com port buffs with "PuregCom()"

i do not get any error msgs or pop ups, it just freezes.

Any ideas.??

Kind regards
kev

«1

Comments

  • : Hi
    : I am trying to send approx 80Kbytes of data out the serial port COM2 using WriteFile.
    :
    : I have used writefile many times for sending only a few hundred bytes, but never a file this big.
    :
    : The PC locks up completely. I cannot even use "ctl,alt,del" it just beeps.
    :
    : Presently i send 10 bytes out with Writefile and then " Sleep(35); "
    : The 10x bytes only take 10msec to TX so the sleep for 35ms is to allow them out the com buffers.
    :
    : I then purge the com port buffs with "PuregCom()"
    :
    : i do not get any error msgs or pop ups, it just freezes.
    :
    : Any ideas.??
    :
    : Kind regards
    : kev
    :
    :


    Post the code.
  • : Hi
    : I am trying to send approx 80Kbytes of data out the serial port COM2 using WriteFile.
    :
    : I have used writefile many times for sending only a few hundred bytes, but never a file this big.
    :
    : The PC locks up completely. I cannot even use "ctl,alt,del" it just beeps.
    :
    : Presently i send 10 bytes out with Writefile and then " Sleep(35); "
    : The 10x bytes only take 10msec to TX so the sleep for 35ms is to allow them out the com buffers.
    :
    : I then purge the com port buffs with "PuregCom()"
    :
    : i do not get any error msgs or pop ups, it just freezes.
    :
    : Any ideas.??
    :
    : Kind regards
    : kev
    :
    :
    Maybe the reciver isn't ready, and he sais so to the sender (your program), and then everything waits for the recivers buffer to empty.
  • : : Hi
    : : I am trying to send approx 80Kbytes of data out the serial port COM2 using WriteFile.
    : :
    : : I have used writefile many times for sending only a few hundred bytes, but never a file this big.
    : :
    : : The PC locks up completely. I cannot even use "ctl,alt,del" it just beeps.
    : :
    : : Presently i send 10 bytes out with Writefile and then " Sleep(35); "
    : : The 10x bytes only take 10msec to TX so the sleep for 35ms is to allow them out the com buffers.
    : :
    : : I then purge the com port buffs with "PuregCom()"
    : :
    : : i do not get any error msgs or pop ups, it just freezes.
    : :
    : : Any ideas.??
    : :
    : : Kind regards
    : : kev
    : :
    : :
    : Maybe the reciver isn't ready, and he sais so to the sender (your program), and then everything waits for the recivers buffer to empty.
    :

    Possibly. however it does send over half the file before it locks up so i dont think that would be it. It sends a good 5000 bytes before it crashes. It behaves as though there is a memory leak but i cut my code own to a for() loop just sending the same bytes each time. This eliminates any other program problems. Its just looping 8000 times, send 10 bytes each loop, sleeps for 35ms, purgecom and then stats again.
    This may be a clue, if i remove the 35ms sleep it will send all 80kB up to 3 times in a row but then it crashs,. With the sleep() it will not send the whole 80kb.
    any thoughts?
    kind regards
    kev

  • : : : Hi
    : : : I am trying to send approx 80Kbytes of data out the serial port COM2 using WriteFile.
    : : :
    : : : I have used writefile many times for sending only a few hundred bytes, but never a file this big.
    : : :
    : : : The PC locks up completely. I cannot even use "ctl,alt,del" it just beeps.
    : : :
    : : : Presently i send 10 bytes out with Writefile and then " Sleep(35); "
    : : : The 10x bytes only take 10msec to TX so the sleep for 35ms is to allow them out the com buffers.
    : : :
    : : : I then purge the com port buffs with "PuregCom()"
    : : :
    : : : i do not get any error msgs or pop ups, it just freezes.
    : : :
    : : : Any ideas.??
    : : :
    : : : Kind regards
    : : : kev
    : : :
    : : :
    : : Maybe the reciver isn't ready, and he sais so to the sender (your program), and then everything waits for the recivers buffer to empty.
    : :
    :
    : Possibly. however it does send over half the file before it locks up so i dont think that would be it. It sends a good 5000 bytes before it crashes. It behaves as though there is a memory leak but i cut my code own to a for() loop just sending the same bytes each time. This eliminates any other program problems. Its just looping 8000 times, send 10 bytes each loop, sleeps for 35ms, purgecom and then stats again.
    : This may be a clue, if i remove the 35ms sleep it will send all 80kB up to 3 times in a row but then it crashs,. With the sleep() it will not send the whole 80kb.
    : any thoughts?
    : kind regards
    : kev
    :
    :
    I think I got it!!

    It freezes after the same amount of time, and after that time it could happen something. What does this mean? nothing!!

    Now to the sullution :-), I have you checked your IRQs?
    It can't be multiple things for one IRQ. Thats the reason why it freezes. In most other cases it would just have stopped, but in this case it freezes. 'New' games do this too, if they use IRQs...
  • : : : : Hi
    : : : : I am trying to send approx 80Kbytes of data out the serial port COM2 using WriteFile.
    : : : :
    : : : : I have used writefile many times for sending only a few hundred bytes, but never a file this big.
    : : : :
    : : : : The PC locks up completely. I cannot even use "ctl,alt,del" it just beeps.
    : : : :
    : : : : Presently i send 10 bytes out with Writefile and then " Sleep(35); "
    : : : : The 10x bytes only take 10msec to TX so the sleep for 35ms is to allow them out the com buffers.
    : : : :
    : : : : I then purge the com port buffs with "PuregCom()"
    : : : :
    : : : : i do not get any error msgs or pop ups, it just freezes.
    : : : :
    : : : : Any ideas.??
    : : : :
    : : : : Kind regards
    : : : : kev
    : : : :
    : : : :
    : : : Maybe the reciver isn't ready, and he sais so to the sender (your program), and then everything waits for the recivers buffer to empty.
    : : :
    : :
    : : Possibly. however it does send over half the file before it locks up so i dont think that would be it. It sends a good 5000 bytes before it crashes. It behaves as though there is a memory leak but i cut my code own to a for() loop just sending the same bytes each time. This eliminates any other program problems. Its just looping 8000 times, send 10 bytes each loop, sleeps for 35ms, purgecom and then stats again.
    : : This may be a clue, if i remove the 35ms sleep it will send all 80kB up to 3 times in a row but then it crashs,. With the sleep() it will not send the whole 80kb.
    : : any thoughts?
    : : kind regards
    : : kev
    : :
    : :
    : I think I got it!!
    :
    : It freezes after the same amount of time, and after that time it could happen something. What does this mean? nothing!!
    :
    : Now to the sullution :-), I have you checked your IRQs?
    : It can't be multiple things for one IRQ. Thats the reason why it freezes. In most other cases it would just have stopped, but in this case it freezes. 'New' games do this too, if they use IRQs...
    :

    Hi
    IRQ? Iknow what they are but but how do i investigate them or fix it?

    kev
  • : : I think I got it!!
    : :
    : : It freezes after the same amount of time, and after that time it could happen something. What does this mean? nothing!!
    : :
    : : Now to the sullution :-), I have you checked your IRQs?
    : : It can't be multiple things for one IRQ. Thats the reason why it freezes. In most other cases it would just have stopped, but in this case it freezes. 'New' games do this too, if they use IRQs...
    : :
    :
    : Hi
    : IRQ? Iknow what they are but but how do i investigate them or fix it?
    :
    : kev
    :
    To investigate look them up in the controll panel if it's a windows sys, on other ones I don't have a clue.

    To fix them the 'manual' says you should consult your hardware manufacturer...
  • : : Hi
    : : I am trying to send approx 80Kbytes of data out the serial port COM2 using WriteFile.
    : :
    : : I have used writefile many times for sending only a few hundred bytes, but never a file this big.
    : :
    : : The PC locks up completely. I cannot even use "ctl,alt,del" it just beeps.
    : :
    : : Presently i send 10 bytes out with Writefile and then " Sleep(35); "
    : : The 10x bytes only take 10msec to TX so the sleep for 35ms is to allow them out the com buffers.
    : :
    : : I then purge the com port buffs with "PuregCom()"
    : :
    : : i do not get any error msgs or pop ups, it just freezes.
    : :
    : : Any ideas.??
    : :
    : : Kind regards
    : : kev
    : :
    : :
    :
    :
    : Post the code.
    :


    Hi
    I hope you can follow this, the text tends to line return makign the code hard to follow.
    Basicly. i
    initialize 9x unsigned chars in array.
    Calcultate the checksum
    TX 9x bytes using writefile, thia takes aprox 10msec
    sleep 35msec
    purge com port 2
    loop back until 8000 loops done.


    DWORD dwNumBytesWritten;

    unsigned char PROGRAMMERMID = 182;
    unsigned char ESCAPEPID = 254;
    unsigned char GAUGEMID = 41;
    unsigned char CONFIGWRITEPID = 192;
    unsigned char NUMBERDATABYTES = 3;
    unsigned char EEPROM_ADDRESS_LSB = 0;
    unsigned char EEPROM_ADDRESS_MSB = 0;
    unsigned char EEPROM_DATA = 0;
    unsigned char CHECKSUM = 0;

    //unsigned char TX_string[10]; //hold data to be txed.
    TX_string[0] = PROGRAMMERMID;
    TX_string[1] = ESCAPEPID;
    TX_string[2] = GAUGEMID;
    TX_string[3] = CONFIGWRITEPID;
    TX_string[4] = NUMBERDATABYTES;
    TX_string[5] = EEPROM_ADDRESS_LSB;
    TX_string[6] = EEPROM_ADDRESS_MSB;
    TX_string[7] = EEPROM_DATA;
    TX_string[8] = CHECKSUM;



    for(i = 0; i < 8191; i++) //loop and write all bytes to the eeprom
    {

    EEPROM_DATA = 0;
    TX_string[7] = EEPROM_DATA;




    //Calculate the checksum
    CHECKSUM = (-1 -(PROGRAMMERMID + ESCAPEPID + GAUGEMID + CONFIGWRITEPID + NUMBERDATABYTES + EEPROM_ADDRESS_LSB + EEPROM_ADDRESS_MSB + EEPROM_DATA)) +1;
    TX_string[8] = CHECKSUM;




    //write 9 bytes to COM 2 @9600bd
    result = WriteFile(hCom_eeprom_write, TX_string, 9, &dwNumBytesWritten, NULL);
    if( (!result) || (dwNumBytesWritten != 9) )
    {
    //WriteFile fialed.
    MessageBox(NULL, "WriteFile failed
    TX to eeprom ERROR", "Error .EC1033: command_write_16bit_EEPROM()", MB_OK);
    }


    Sleep(35);



    //Clear the RS232 TX buffer and report any errors
    if(!PurgeComm(hCom_eeprom_write,PURGE_TXCLEAR)) //clears rx buffer. Purgcom can also clear tx buff etc.
    {
    CHAR szBuf[80];
    LPSTR lpszFunction;
    DWORD dw = GetLastError();

    sprintf(szBuf, "%s PurgeComm hCom_2 TX Failed at 1001: GetLastError returned %u
    ", lpszFunction, dw);
    MessageBox(NULL, szBuf, "Error .EC0033", MB_OK);
    Error_Code_Logger(szBuf);
    ExitProcess(dw);
    //MessageBox(hwnd, "PurgeComm TX Failed", "Test Mode", MB_OK);
    }


    //Clear the RS232 TRX buffer and report any errors
    if(!PurgeComm(hCom_eeprom_write,PURGE_RXCLEAR)) //clears rx buffer. Purgcom can also clear tx buff etc.
    {
    CHAR szBuf[80];
    LPSTR lpszFunction;
    DWORD dw = GetLastError();

    sprintf(szBuf, "%s PurgeComm hCom_2 RX Failed: GetLastError returned %u
    ", lpszFunction, dw);
    MessageBox(NULL, szBuf, "Error .EC0034", MB_OK);
    Error_Code_Logger(szBuf);
    ExitProcess(dw);
    //MessageBox(hwnd, "PurgeComm TX Failed", "Test Mode", MB_OK);
    }




    } //close... for(i = 0; i 8121; i++) //loop and write all bytes to the eeprom


  • : : : I think I got it!!
    : : :
    : : : It freezes after the same amount of time, and after that time it could happen something. What does this mean? nothing!!
    : : :
    : : : Now to the sullution :-), I have you checked your IRQs?
    : : : It can't be multiple things for one IRQ. Thats the reason why it freezes. In most other cases it would just have stopped, but in this case it freezes. 'New' games do this too, if they use IRQs...
    : : :
    : :
    : : Hi
    : : IRQ? Iknow what they are but but how do i investigate them or fix it?
    : :
    : : kev
    : :
    : To investigate look them up in the controll panel if it's a windows sys, on other ones I don't have a clue.
    :
    : To fix them the 'manual' says you should consult your hardware manufacturer...
    :

    Hi
    Thanks for the IRQ tip, i did have a conflict between com2 and com3 having the same IRQ. I disabled com3 as i am not using it. I am sending data out com2. However, it still freezes.

    cheers
    kev
  • : : : : I think I got it!!
    : : : :
    : : : : It freezes after the same amount of time, and after that time it could happen something. What does this mean? nothing!!
    : : : :
    : : : : Now to the sullution :-), I have you checked your IRQs?
    : : : : It can't be multiple things for one IRQ. Thats the reason why it freezes. In most other cases it would just have stopped, but in this case it freezes. 'New' games do this too, if they use IRQs...
    : : : :
    : : :
    : : : Hi
    : : : IRQ? Iknow what they are but but how do i investigate them or fix it?
    : : :
    : : : kev
    : : :
    : : To investigate look them up in the controll panel if it's a windows sys, on other ones I don't have a clue.
    : :
    : : To fix them the 'manual' says you should consult your hardware manufacturer...
    : :
    :
    : Hi
    : Thanks for the IRQ tip, i did have a conflict between com2 and com3 having the same IRQ. I disabled com3 as i am not using it. I am sending data out com2. However, it still freezes.
    :
    : cheers
    : kev
    :
    Com2 and Com3 always have the same irq...
    The same for Com1 and Com4...

    So I wasn't right...
  • : : : : : I think I got it!!
    : : : : :
    : : : : : It freezes after the same amount of time, and after that time it could happen something. What does this mean? nothing!!
    : : : : :
    : : : : : Now to the sullution :-), I have you checked your IRQs?
    : : : : : It can't be multiple things for one IRQ. Thats the reason why it freezes. In most other cases it would just have stopped, but in this case it freezes. 'New' games do this too, if they use IRQs...
    : : : : :
    : : : :
    : : : : Hi
    : : : : IRQ? Iknow what they are but but how do i investigate them or fix it?
    : : : :
    : : : : kev
    : : : :
    : : : To investigate look them up in the controll panel if it's a windows sys, on other ones I don't have a clue.
    : : :
    : : : To fix them the 'manual' says you should consult your hardware manufacturer...
    : : :
    : :
    : : Hi
    : : Thanks for the IRQ tip, i did have a conflict between com2 and com3 having the same IRQ. I disabled com3 as i am not using it. I am sending data out com2. However, it still freezes.
    : :
    : : cheers
    : : kev
    : :
    : Com2 and Com3 always have the same irq...
    : The same for Com1 and Com4...
    :
    : So I wasn't right...
    :
    ok
    i wonder if its a timing thing or a buffer over run?
    Im just hoping i will say something that will trigger a solution from some body?
    cheers
    kev
  • : Hi
    : I hope you can follow this, the text tends to line return makign the code hard to follow.

    [blue]Use code tags.

    [leftbr]code[rightbr]
    printf("Hello world");
    [leftbr]/code[rightbr]
    [/blue]

    : Basicly. i
    : initialize 9x unsigned chars in array.
    : Calcultate the checksum
    : TX 9x bytes using writefile, thia takes aprox 10msec
    : sleep 35msec
    : purge com port 2
    : loop back until 8000 loops done.
    :


    [code]
    : DWORD dwNumBytesWritten;
    :
    : unsigned char PROGRAMMERMID = 182;
    : unsigned char ESCAPEPID = 254;
    : unsigned char GAUGEMID = 41;
    : unsigned char CONFIGWRITEPID = 192;
    : unsigned char NUMBERDATABYTES = 3;
    : unsigned char EEPROM_ADDRESS_LSB = 0;
    : unsigned char EEPROM_ADDRESS_MSB = 0;
    : unsigned char EEPROM_DATA = 0;
    : unsigned char CHECKSUM = 0;
    :
    : //unsigned char TX_string[10]; //hold data to be txed.
    : TX_string[0] = PROGRAMMERMID;
    : TX_string[1] = ESCAPEPID;
    : TX_string[2] = GAUGEMID;
    : TX_string[3] = CONFIGWRITEPID;
    : TX_string[4] = NUMBERDATABYTES;
    : TX_string[5] = EEPROM_ADDRESS_LSB;
    : TX_string[6] = EEPROM_ADDRESS_MSB;
    : TX_string[7] = EEPROM_DATA;
    : TX_string[8] = CHECKSUM;
    :
    :
    :
    : for(i = 0; i < 8191; i++) //loop and write all bytes to the eeprom
    : {
    :
    : EEPROM_DATA = 0;
    : TX_string[7] = EEPROM_DATA;
    :
    :
    :
    :
    : //Calculate the checksum
    : CHECKSUM = (-1 -(PROGRAMMERMID + ESCAPEPID + GAUGEMID + CONFIGWRITEPID + NUMBERDATABYTES + EEPROM_ADDRESS_LSB + EEPROM_ADDRESS_MSB + EEPROM_DATA)) +1;
    : TX_string[8] = CHECKSUM;
    :
    :
    :
    :
    : //write 9 bytes to COM 2 @9600bd
    : result = WriteFile(hCom_eeprom_write, TX_string, 9, &dwNumBytesWritten, NULL);
    : if( (!result) || (dwNumBytesWritten != 9) )
    : {
    : //WriteFile fialed.
    : MessageBox(NULL, "WriteFile failed
    TX to eeprom ERROR", "Error .EC1033: command_write_16bit_EEPROM()", MB_OK);
    : }
    :
    :
    : Sleep(35);
    :
    :
    :
    : //Clear the RS232 TX buffer and report any errors
    : if(!PurgeComm(hCom_eeprom_write,PURGE_TXCLEAR)) //clears rx buffer. Purgcom can also clear tx buff etc.
    : {
    : CHAR szBuf[80];
    : LPSTR lpszFunction;
    : DWORD dw = GetLastError();
    :
    : sprintf(szBuf, "%s PurgeComm hCom_2 TX Failed at 1001: GetLastError returned %u
    ", lpszFunction, dw);
    : MessageBox(NULL, szBuf, "Error .EC0033", MB_OK);
    : Error_Code_Logger(szBuf);
    : ExitProcess(dw);
    : //MessageBox(hwnd, "PurgeComm TX Failed", "Test Mode", MB_OK);
    : }
    :
    :
    : //Clear the RS232 TRX buffer and report any errors
    : if(!PurgeComm(hCom_eeprom_write,PURGE_RXCLEAR)) //clears rx buffer. Purgcom can also clear tx buff etc.
    : {
    : CHAR szBuf[80];
    : LPSTR lpszFunction;
    : DWORD dw = GetLastError();
    :
    : sprintf(szBuf, "%s PurgeComm hCom_2 RX Failed: GetLastError returned %u
    ", lpszFunction, dw);
    : MessageBox(NULL, szBuf, "Error .EC0034", MB_OK);
    : Error_Code_Logger(szBuf);
    : ExitProcess(dw);
    : //MessageBox(hwnd, "PurgeComm TX Failed", "Test Mode", MB_OK);
    : }
    :
    :
    :
    :
    : } //close... for(i = 0; i 8121; i++) //loop and write all bytes to the eeprom
    :
    :
    :

    [/code]


    [blue]
    I can't see any bugs in the code, but since you say that the PC freezes... do you get the same behaviour on another PC?

    Also, there might be problems in the code that you didn't post, that is opening the com port. I know that using WriteFile() on an invalid HANDLE can give you strange errors.
    [/blue]
  • : : Hi
    : : I hope you can follow this, the text tends to line return makign the code hard to follow.
    :
    : [blue]Use code tags.
    :
    : [leftbr]code[rightbr]
    : printf("Hello world");
    : [leftbr]/code[rightbr]
    : [/blue]
    :
    : : Basicly. i
    : : initialize 9x unsigned chars in array.
    : : Calcultate the checksum
    : : TX 9x bytes using writefile, thia takes aprox 10msec
    : : sleep 35msec
    : : purge com port 2
    : : loop back until 8000 loops done.
    : :
    :
    :
    : [code]
    : : DWORD dwNumBytesWritten;
    : :
    : : unsigned char PROGRAMMERMID = 182;
    : : unsigned char ESCAPEPID = 254;
    : : unsigned char GAUGEMID = 41;
    : : unsigned char CONFIGWRITEPID = 192;
    : : unsigned char NUMBERDATABYTES = 3;
    : : unsigned char EEPROM_ADDRESS_LSB = 0;
    : : unsigned char EEPROM_ADDRESS_MSB = 0;
    : : unsigned char EEPROM_DATA = 0;
    : : unsigned char CHECKSUM = 0;
    : :
    : : //unsigned char TX_string[10]; //hold data to be txed.
    : : TX_string[0] = PROGRAMMERMID;
    : : TX_string[1] = ESCAPEPID;
    : : TX_string[2] = GAUGEMID;
    : : TX_string[3] = CONFIGWRITEPID;
    : : TX_string[4] = NUMBERDATABYTES;
    : : TX_string[5] = EEPROM_ADDRESS_LSB;
    : : TX_string[6] = EEPROM_ADDRESS_MSB;
    : : TX_string[7] = EEPROM_DATA;
    : : TX_string[8] = CHECKSUM;
    : :
    : :
    : :
    : : for(i = 0; i < 8191; i++) //loop and write all bytes to the eeprom
    : : {
    : :
    : : EEPROM_DATA = 0;
    : : TX_string[7] = EEPROM_DATA;
    : :
    : :
    : :
    : :
    : : //Calculate the checksum
    : : CHECKSUM = (-1 -(PROGRAMMERMID + ESCAPEPID + GAUGEMID + CONFIGWRITEPID + NUMBERDATABYTES + EEPROM_ADDRESS_LSB + EEPROM_ADDRESS_MSB + EEPROM_DATA)) +1;
    : : TX_string[8] = CHECKSUM;
    : :
    : :
    : :
    : :
    : : //write 9 bytes to COM 2 @9600bd
    : : result = WriteFile(hCom_eeprom_write, TX_string, 9, &dwNumBytesWritten, NULL);
    : : if( (!result) || (dwNumBytesWritten != 9) )
    : : {
    : : //WriteFile fialed.
    : : MessageBox(NULL, "WriteFile failed
    TX to eeprom ERROR", "Error .EC1033: command_write_16bit_EEPROM()", MB_OK);
    : : }
    : :
    : :
    : : Sleep(35);
    : :
    : :
    : :
    : : //Clear the RS232 TX buffer and report any errors
    : : if(!PurgeComm(hCom_eeprom_write,PURGE_TXCLEAR)) //clears rx buffer. Purgcom can also clear tx buff etc.
    : : {
    : : CHAR szBuf[80];
    : : LPSTR lpszFunction;
    : : DWORD dw = GetLastError();
    : :
    : : sprintf(szBuf, "%s PurgeComm hCom_2 TX Failed at 1001: GetLastError returned %u
    ", lpszFunction, dw);
    : : MessageBox(NULL, szBuf, "Error .EC0033", MB_OK);
    : : Error_Code_Logger(szBuf);
    : : ExitProcess(dw);
    : : //MessageBox(hwnd, "PurgeComm TX Failed", "Test Mode", MB_OK);
    : : }
    : :
    : :
    : : //Clear the RS232 TRX buffer and report any errors
    : : if(!PurgeComm(hCom_eeprom_write,PURGE_RXCLEAR)) //clears rx buffer. Purgcom can also clear tx buff etc.
    : : {
    : : CHAR szBuf[80];
    : : LPSTR lpszFunction;
    : : DWORD dw = GetLastError();
    : :
    : : sprintf(szBuf, "%s PurgeComm hCom_2 RX Failed: GetLastError returned %u
    ", lpszFunction, dw);
    : : MessageBox(NULL, szBuf, "Error .EC0034", MB_OK);
    : : Error_Code_Logger(szBuf);
    : : ExitProcess(dw);
    : : //MessageBox(hwnd, "PurgeComm TX Failed", "Test Mode", MB_OK);
    : : }
    : :
    : :
    : :
    : :
    : : } //close... for(i = 0; i 8121; i++) //loop and write all bytes to the eeprom
    : :
    : :
    : :
    :
    : [/code]
    :
    :
    : [blue]
    : I can't see any bugs in the code, but since you say that the PC freezes... do you get the same behaviour on another PC?
    :
    : Also, there might be problems in the code that you didn't post, that is opening the com port. I know that using WriteFile() on an invalid HANDLE can give you strange errors.
    : [/blue]
    :


    Thanks
    here is the com2 set up code i use. I have tried changing the times out to 1000 and the inQueue and outQueue to 200,000. It still freezes.
    I havent tried it on another pc, i wish to have it work on all pcs.
    So far, all i can do is write up to 1000 packets (9 bytes each pkt) reliably. I am considering just calling the writefile loop 8x to get the 8000 packets (80KByte)i require.

    [code]
    void set_com_port_2(void)
    {
    /* set up a serial port. */


    DCB dcb;
    //HANDLE hCom_2; is global scope
    BOOL fSuccess;

    char pcCommPort[6] = "COM2"; //DEFAULT SETTING

    char a = 0x00;
    DWORD dwInQueue = 2000; //was 2000
    DWORD dwOutQueue = 2000; //was 2000



    hCom_2 = CreateFile( pcCommPort,
    GENERIC_READ | GENERIC_WRITE,
    0, // must be opened with exclusive-access
    NULL, // no security attributes
    OPEN_EXISTING, // must use OPEN_EXISTING
    0, // not overlapped I/O
    NULL // hTemplate must be NULL for comm devices
    );





    if (hCom_2 == INVALID_HANDLE_VALUE)
    {

    CHAR szBuf[80];
    LPSTR lpszFunction;
    DWORD dw = GetLastError();
    sprintf(szBuf, "%x CreateFile failed Failed COM2: GetLastError returned %u
    ", lpszFunction, dw);
    MessageBox(NULL, szBuf, "Error. EC0016", MB_OK);

    ExitProcess(dw);
    }


    //set up the RX and TX buffer size
    fSuccess = SetupComm(hCom_2, dwInQueue, dwOutQueue);
    if (!fSuccess)
    {

    CHAR szBuf[80];
    LPSTR lpszFunction;
    DWORD dw = GetLastError();
    sprintf(szBuf, "%s SetupComm failed COM2: GetLastError returned %u
    ", lpszFunction, dw);
    MessageBox(NULL, szBuf, "Error. EC0017", MB_OK);

    ExitProcess(dw);

    }


    // Build on the current configuration, and skip setting the size
    // of the input and output buffers with SetupComm.
    fSuccess = GetCommState(hCom_2, &dcb);

    if (!fSuccess)
    {

    CHAR szBuf[80];
    LPSTR lpszFunction;
    DWORD dw = GetLastError();
    sprintf(szBuf, "%s GetCommState failed COM2: GetLastError returned %u
    ", lpszFunction, dw);
    MessageBox(NULL, szBuf, "Error, EC0018", MB_OK);

    ExitProcess(dw);

    }



    // Fill in DCB: 9,600 bps, 8 data bits, no parity, and 1 stop bit.


    dcb.BaudRate = CBR_9600; //CBR_9600; //CBR_9600; // set the baud rate
    dcb.ByteSize = 8; // data size, xmit, and rcv
    dcb.Parity = NOPARITY; // no parity bit
    dcb.StopBits = ONESTOPBIT; // one stop bit
    dcb.fBinary = TRUE;
    //dcb.fParity = TRUE;

    fSuccess = SetCommState(hCom_2, &dcb);

    if (!fSuccess)
    {


    CHAR szBuf[80];
    LPSTR lpszFunction;
    DWORD dw = GetLastError();
    sprintf(szBuf, "%s SetCommState failed COM2: GetLastError returned %u
    ", lpszFunction, dw);
    MessageBox(NULL, szBuf, "Error EC0019", MB_OK);

    ExitProcess(dw);

    }


    //*********reconfigur com1 time outs for shorter time out period***********//

    //set up time outs for com port.
    //shorten time outs to prevent pc hanging up waiting for a message from gauge that will never come.
    //rx will time out in 1 millisecond
    GetCommTimeouts(hCom_2, &cto);
    cto.ReadIntervalTimeout= 0; //was 0
    cto.ReadTotalTimeoutMultiplier= 0; //was 0.
    cto.ReadTotalTimeoutConstant= 1; //was 1
    cto.WriteTotalTimeoutMultiplier= 0; //was 0
    cto.WriteTotalTimeoutConstant= 0; //was 0
    SetCommTimeouts(hCom_2, &cto);









    //CloseHandle(hCom);


    //Clear the RS232 TX buffer and report any errors
    if(!PurgeComm(hCom_2,PURGE_TXCLEAR)) //clears rx buffer. Purgcom can also clear tx buff etc.
    {
    CHAR szBuf[80];
    LPSTR lpszFunction;
    DWORD dw = GetLastError();

    sprintf(szBuf, "%s PurgeComm TX Failed: GetLastError returned %u
    Set Com Port 2", lpszFunction, dw);
    MessageBox(NULL, szBuf, "Error EC0020", MB_OK);

    ExitProcess(dw);

    }


    //Clear the RS232 TRX buffer and report any errors
    if(!PurgeComm(hCom_2,PURGE_RXCLEAR)) //clears rx buffer. Purgcom can also clear tx buff etc.
    {
    CHAR szBuf[80];
    LPSTR lpszFunction;
    DWORD dw = GetLastError();

    sprintf(szBuf, "%s PurgeComm RX Failed: GetLastError returned %u
    ", lpszFunction, dw);
    MessageBox(NULL, szBuf, "Error. EC0021", MB_OK);

    ExitProcess(dw);

    }



    return;

    }
    [/code]

    Any thoughts?

    Thanks for all you help.

    cheers
    kev

  • : : : : : I think I got it!!
    : : : : :
    : : : : : It freezes after the same amount of time, and after that time it could happen something. What does this mean? nothing!!
    : : : : :
    : : : : : Now to the sullution :-), I have you checked your IRQs?
    : : : : : It can't be multiple things for one IRQ. Thats the reason why it freezes. In most other cases it would just have stopped, but in this case it freezes. 'New' games do this too, if they use IRQs...
    : : : : :
    : : : :
    : : : : Hi
    : : : : IRQ? Iknow what they are but but how do i investigate them or fix it?
    : : : :
    : : : : kev
    : : : :
    : : : To investigate look them up in the controll panel if it's a windows sys, on other ones I don't have a clue.
    : : :
    : : : To fix them the 'manual' says you should consult your hardware manufacturer...
    : : :
    : :
    : : Hi
    : : Thanks for the IRQ tip, i did have a conflict between com2 and com3 having the same IRQ. I disabled com3 as i am not using it. I am sending data out com2. However, it still freezes.
    : :
    : : cheers
    : : kev
    : :
    : Com2 and Com3 always have the same irq...
    : The same for Com1 and Com4...
    :
    : So I wasn't right...
    :

    Hi
    I just tried to send an 80K text file out com2 using HyperTerminal. The PC locked up part way through the transmission. So it does not look like a code issue. Perhaps there is a file limit on com2 tx? or perhaps it is something to do with the hardware attached to the com2. The hardware doesnt do anything, no acks or handshaking. In fact it should ignore the transmission. However, it looks like i can stop picking at the code.
    THANK YOU ALL FFOR YOU HELP.
    kev

  • : : Hi
    : : I hope you can follow this, the text tends to line return makign the code hard to follow.
    :
    : [blue]Use code tags.
    :
    : [leftbr]code[rightbr]
    : printf("Hello world");
    : [leftbr]/code[rightbr]
    : [/blue]
    :
    : : Basicly. i
    : : initialize 9x unsigned chars in array.
    : : Calcultate the checksum
    : : TX 9x bytes using writefile, thia takes aprox 10msec
    : : sleep 35msec
    : : purge com port 2
    : : loop back until 8000 loops done.
    : :
    :
    :
    : [code]
    : : DWORD dwNumBytesWritten;
    : :
    : : unsigned char PROGRAMMERMID = 182;
    : : unsigned char ESCAPEPID = 254;
    : : unsigned char GAUGEMID = 41;
    : : unsigned char CONFIGWRITEPID = 192;
    : : unsigned char NUMBERDATABYTES = 3;
    : : unsigned char EEPROM_ADDRESS_LSB = 0;
    : : unsigned char EEPROM_ADDRESS_MSB = 0;
    : : unsigned char EEPROM_DATA = 0;
    : : unsigned char CHECKSUM = 0;
    : :
    : : //unsigned char TX_string[10]; //hold data to be txed.
    : : TX_string[0] = PROGRAMMERMID;
    : : TX_string[1] = ESCAPEPID;
    : : TX_string[2] = GAUGEMID;
    : : TX_string[3] = CONFIGWRITEPID;
    : : TX_string[4] = NUMBERDATABYTES;
    : : TX_string[5] = EEPROM_ADDRESS_LSB;
    : : TX_string[6] = EEPROM_ADDRESS_MSB;
    : : TX_string[7] = EEPROM_DATA;
    : : TX_string[8] = CHECKSUM;
    : :
    : :
    : :
    : : for(i = 0; i < 8191; i++) //loop and write all bytes to the eeprom
    : : {
    : :
    : : EEPROM_DATA = 0;
    : : TX_string[7] = EEPROM_DATA;
    : :
    : :
    : :
    : :
    : : //Calculate the checksum
    : : CHECKSUM = (-1 -(PROGRAMMERMID + ESCAPEPID + GAUGEMID + CONFIGWRITEPID + NUMBERDATABYTES + EEPROM_ADDRESS_LSB + EEPROM_ADDRESS_MSB + EEPROM_DATA)) +1;
    : : TX_string[8] = CHECKSUM;
    : :
    : :
    : :
    : :
    : : //write 9 bytes to COM 2 @9600bd
    : : result = WriteFile(hCom_eeprom_write, TX_string, 9, &dwNumBytesWritten, NULL);
    : : if( (!result) || (dwNumBytesWritten != 9) )
    : : {
    : : //WriteFile fialed.
    : : MessageBox(NULL, "WriteFile failed
    TX to eeprom ERROR", "Error .EC1033: command_write_16bit_EEPROM()", MB_OK);
    : : }
    : :
    : :
    : : Sleep(35);
    : :
    : :
    : :
    : : //Clear the RS232 TX buffer and report any errors
    : : if(!PurgeComm(hCom_eeprom_write,PURGE_TXCLEAR)) //clears rx buffer. Purgcom can also clear tx buff etc.
    : : {
    : : CHAR szBuf[80];
    : : LPSTR lpszFunction;
    : : DWORD dw = GetLastError();
    : :
    : : sprintf(szBuf, "%s PurgeComm hCom_2 TX Failed at 1001: GetLastError returned %u
    ", lpszFunction, dw);
    : : MessageBox(NULL, szBuf, "Error .EC0033", MB_OK);
    : : Error_Code_Logger(szBuf);
    : : ExitProcess(dw);
    : : //MessageBox(hwnd, "PurgeComm TX Failed", "Test Mode", MB_OK);
    : : }
    : :
    : :
    : : //Clear the RS232 TRX buffer and report any errors
    : : if(!PurgeComm(hCom_eeprom_write,PURGE_RXCLEAR)) //clears rx buffer. Purgcom can also clear tx buff etc.
    : : {
    : : CHAR szBuf[80];
    : : LPSTR lpszFunction;
    : : DWORD dw = GetLastError();
    : :
    : : sprintf(szBuf, "%s PurgeComm hCom_2 RX Failed: GetLastError returned %u
    ", lpszFunction, dw);
    : : MessageBox(NULL, szBuf, "Error .EC0034", MB_OK);
    : : Error_Code_Logger(szBuf);
    : : ExitProcess(dw);
    : : //MessageBox(hwnd, "PurgeComm TX Failed", "Test Mode", MB_OK);
    : : }
    : :
    : :
    : :
    : :
    : : } //close... for(i = 0; i 8121; i++) //loop and write all bytes to the eeprom
    : :
    : :
    : :
    :
    : [/code]
    :
    :
    : [blue]
    : I can't see any bugs in the code, but since you say that the PC freezes... do you get the same behaviour on another PC?
    :
    : Also, there might be problems in the code that you didn't post, that is opening the com port. I know that using WriteFile() on an invalid HANDLE can give you strange errors.
    : [/blue]
    :




    Hi
    I have discovered that the device connected to the com port is echo ing all bytes i send out. That means about 80KB of data is arriving at the COM port for RX whilst i am TXing?
    Do you know how this may be causing the pc to lock up?

    kind regards
    kev

  • : : : Hi
    : : : I hope you can follow this, the text tends to line return makign the code hard to follow.
    : :
    : : [blue]Use code tags.
    : :
    : : [leftbr]code[rightbr]
    : : printf("Hello world");
    : : [leftbr]/code[rightbr]
    : : [/blue]
    : :
    : : : Basicly. i
    : : : initialize 9x unsigned chars in array.
    : : : Calcultate the checksum
    : : : TX 9x bytes using writefile, thia takes aprox 10msec
    : : : sleep 35msec
    : : : purge com port 2
    : : : loop back until 8000 loops done.
    : : :
    : :
    : :
    : : [code]
    : : : DWORD dwNumBytesWritten;
    : : :
    : : : unsigned char PROGRAMMERMID = 182;
    : : : unsigned char ESCAPEPID = 254;
    : : : unsigned char GAUGEMID = 41;
    : : : unsigned char CONFIGWRITEPID = 192;
    : : : unsigned char NUMBERDATABYTES = 3;
    : : : unsigned char EEPROM_ADDRESS_LSB = 0;
    : : : unsigned char EEPROM_ADDRESS_MSB = 0;
    : : : unsigned char EEPROM_DATA = 0;
    : : : unsigned char CHECKSUM = 0;
    : : :
    : : : //unsigned char TX_string[10]; //hold data to be txed.
    : : : TX_string[0] = PROGRAMMERMID;
    : : : TX_string[1] = ESCAPEPID;
    : : : TX_string[2] = GAUGEMID;
    : : : TX_string[3] = CONFIGWRITEPID;
    : : : TX_string[4] = NUMBERDATABYTES;
    : : : TX_string[5] = EEPROM_ADDRESS_LSB;
    : : : TX_string[6] = EEPROM_ADDRESS_MSB;
    : : : TX_string[7] = EEPROM_DATA;
    : : : TX_string[8] = CHECKSUM;
    : : :
    : : :
    : : :
    : : : for(i = 0; i < 8191; i++) //loop and write all bytes to the eeprom
    : : : {
    : : :
    : : : EEPROM_DATA = 0;
    : : : TX_string[7] = EEPROM_DATA;
    : : :
    : : :
    : : :
    : : :
    : : : //Calculate the checksum
    : : : CHECKSUM = (-1 -(PROGRAMMERMID + ESCAPEPID + GAUGEMID + CONFIGWRITEPID + NUMBERDATABYTES + EEPROM_ADDRESS_LSB + EEPROM_ADDRESS_MSB + EEPROM_DATA)) +1;
    : : : TX_string[8] = CHECKSUM;
    : : :
    : : :
    : : :
    : : :
    : : : //write 9 bytes to COM 2 @9600bd
    : : : result = WriteFile(hCom_eeprom_write, TX_string, 9, &dwNumBytesWritten, NULL);
    : : : if( (!result) || (dwNumBytesWritten != 9) )
    : : : {
    : : : //WriteFile fialed.
    : : : MessageBox(NULL, "WriteFile failed
    TX to eeprom ERROR", "Error .EC1033: command_write_16bit_EEPROM()", MB_OK);
    : : : }
    : : :
    : : :
    : : : Sleep(35);
    : : :
    : : :
    : : :
    : : : //Clear the RS232 TX buffer and report any errors
    : : : if(!PurgeComm(hCom_eeprom_write,PURGE_TXCLEAR)) //clears rx buffer. Purgcom can also clear tx buff etc.
    : : : {
    : : : CHAR szBuf[80];
    : : : LPSTR lpszFunction;
    : : : DWORD dw = GetLastError();
    : : :
    : : : sprintf(szBuf, "%s PurgeComm hCom_2 TX Failed at 1001: GetLastError returned %u
    ", lpszFunction, dw);
    : : : MessageBox(NULL, szBuf, "Error .EC0033", MB_OK);
    : : : Error_Code_Logger(szBuf);
    : : : ExitProcess(dw);
    : : : //MessageBox(hwnd, "PurgeComm TX Failed", "Test Mode", MB_OK);
    : : : }
    : : :
    : : :
    : : : //Clear the RS232 TRX buffer and report any errors
    : : : if(!PurgeComm(hCom_eeprom_write,PURGE_RXCLEAR)) //clears rx buffer. Purgcom can also clear tx buff etc.
    : : : {
    : : : CHAR szBuf[80];
    : : : LPSTR lpszFunction;
    : : : DWORD dw = GetLastError();
    : : :
    : : : sprintf(szBuf, "%s PurgeComm hCom_2 RX Failed: GetLastError returned %u
    ", lpszFunction, dw);
    : : : MessageBox(NULL, szBuf, "Error .EC0034", MB_OK);
    : : : Error_Code_Logger(szBuf);
    : : : ExitProcess(dw);
    : : : //MessageBox(hwnd, "PurgeComm TX Failed", "Test Mode", MB_OK);
    : : : }
    : : :
    : : :
    : : :
    : : :
    : : : } //close... for(i = 0; i 8121; i++) //loop and write all bytes to the eeprom
    : : :
    : : :
    : : :
    : :
    : : [/code]
    : :
    : :
    : : [blue]
    : : I can't see any bugs in the code, but since you say that the PC freezes... do you get the same behaviour on another PC?
    : :
    : : Also, there might be problems in the code that you didn't post, that is opening the com port. I know that using WriteFile() on an invalid HANDLE can give you strange errors.
    : : [/blue]
    : :
    :
    :
    :
    :
    : Hi
    : I have discovered that the device connected to the com port is echo ing all bytes i send out. That means about 80KB of data is arriving at the COM port for RX whilst i am TXing?
    : Do you know how this may be causing the pc to lock up?
    :
    : kind regards
    : kev
    :
    :


    [blue]COM port init code looks ok.

    If you don't read the rx buffer it will be filled and then start to discard the bytes it gets. It won't affect your program.

    I'd say there is something wrong with the PC's COM port.

    [/blue]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories