Results 1 to 2 of 2

Thread: See if you can solve this one ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Posts
    105

    Talking

    Well , I had managed to write a program - sampling input from a datalogger system , with the mscomm32.ocx . but I have few problems with it and I thought maybe you could help , because I have no one to turn to.

    My problem with the communication is :

    To sample input/s from the datalogger you have to send a binary block cointaining the input/s you want , in return the datalogger send back a binary block cointaining the answer (value) of the input/s you reqested. - all done through the serial port com (1).
    Because I want the program to sample all the time I made this block communication in a Do - Loop thing :

    Do
    Call block_out ' this block contain the data send to datalogger requesting inputs
    MSComm1.Output = hb ' the hb is an array contain the message
    Call delay(0.2) ' wait for 0.2 sec. for the datalogger to send back data
    Do While MSComm1.InBufferCount > 0
    DoEvents ' this is for letting the mscomm_oncomm event to fire
    Loop
    ReDim Preserve rcv(f - 1)
    Call block_in ' this sub take the rcv array , analyze it and shows the sampled inputs on a textbox
    Loop

    Private Sub MSComm1_OnComm()

    Select Case MSComm1.CommEvent

    ' when receiving byte - insert to the rcv() array
    Case comEvReceive
    buf = MSComm1.Input ' the buf declare as variant
    rcv = buf

    End Select

    End Sub


    The mscomm has an event called mscomm_oncomm , which fired when you recieve data in the recieve buffer.
    My problem started when I use this Do - Loop thing to continue the communication - The mscomm_oncom didn't fire because their is an endless loop (the above code) . So to fix it I use the Doevents command , and it did fix the problem , but then another problem poped up :

    Because the Doevents command enable events to happen, than for example when I drag the program form or click on it or any other event that happen while the program runs (even if this event doesn't soppuse to do a thing) the communication stops till this event is finished.

    Well I know that its happen because the Doevents command but I can't put it out unless you have a solution.
    Maybe I need win32 api calls for communication.
    I think that I need this communication to work on a different thread - is it possible ? should I write a dll ?

    I will be greatfull if you will help me , because for now I'm stuck with this program and I gess you know the feeling ...

    Thanks in advance Tomer ([email protected])


  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Holden Beach NC
    Posts
    85
    Originally posted by moyalt
    Well , I had managed to write a program - sampling input from a datalogger system , with the mscomm32.ocx . but I have few problems with it and I thought maybe you could help , because I have no one to turn to.

    My problem with the communication is :

    To sample input/s from the datalogger you have to send a binary block cointaining the input/s you want , in return the datalogger send back a binary block cointaining the answer (value) of the input/s you reqested. - all done through the serial port com (1).
    Because I want the program to sample all the time I made this block communication in a Do - Loop thing :

    Do
    Call block_out ' this block contain the data send to datalogger requesting inputs
    MSComm1.Output = hb ' the hb is an array contain the message
    Call delay(0.2) ' wait for 0.2 sec. for the datalogger to send back data
    Do While MSComm1.InBufferCount > 0
    DoEvents ' this is for letting the mscomm_oncomm event to fire
    Loop
    ReDim Preserve rcv(f - 1)
    Call block_in ' this sub take the rcv array , analyze it and shows the sampled inputs on a textbox
    Loop

    Private Sub MSComm1_OnComm()

    Select Case MSComm1.CommEvent

    ' when receiving byte - insert to the rcv() array
    Case comEvReceive
    buf = MSComm1.Input ' the buf declare as variant
    rcv = buf

    End Select

    End Sub


    The mscomm has an event called mscomm_oncomm , which fired when you recieve data in the recieve buffer.
    My problem started when I use this Do - Loop thing to continue the communication - The mscomm_oncom didn't fire because their is an endless loop (the above code) . So to fix it I use the Doevents command , and it did fix the problem , but then another problem poped up :

    Because the Doevents command enable events to happen, than for example when I drag the program form or click on it or any other event that happen while the program runs (even if this event doesn't soppuse to do a thing) the communication stops till this event is finished.

    Well I know that its happen because the Doevents command but I can't put it out unless you have a solution.
    Maybe I need win32 api calls for communication.
    I think that I need this communication to work on a different thread - is it possible ? should I write a dll ?

    I will be greatfull if you will help me , because for now I'm stuck with this program and I gess you know the feeling ...

    Thanks in advance Tomer ([email protected])

    Tomer,

    I responded via e-mail, but since you have posted this here I will briefly outline the suggestion that I e-mailed to you so that others my critique//criticize as needed.

    I suggested that instead of a do loop that you place a Timer control on the form where the mscomm control is. Declare a global variable boolWait. From either a list control or database recordset create a list of call strings. When the _OnTimer event is triggered have it check boolWait. If boolWait = true then nothing happens, if boolEait=False then send the string and set boolWait=TRUE. When the _OnComm event is triggered handle the data and return boolWait = FALSE. This will allow Windows to do normal processing in the background as it likes to do when it is waiting for an event. There is probably a better solution, but I think that this will work.

    Hunter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width