No announcement yet.

Electronics application with PBWin

  • Filter
  • Time
  • Show
Clear All
new posts

  • Electronics application with PBWin

    Hello all

    Whynot somebody post here in the sources forums none of serial communications applications such as examples, ideas, controls with an microcontrollers.

    I would like to write an serial communication for control the temperature with an microcontroller and read en write the data via serial communications and the tool is perfect in PB

    I hope that someboy post serial communications on the source forums for electronic developers that works with microcontrollers

    Kind regards

  • #2
    Hi Stephane,

    I don't personally do much with serial ports, but at my VB site I have a fair amount of information on the topic - especially links to code that should be convertible to a PowerBASIC application.

    See if this helps any.


    • #3
      I work with Serial Ports (both virtual and real) all the time to communicate with Stepper-Motor controllers and Digital readouts. For the most part they are all communication with a micro controller, so its really just a matter of communication protocols that need to be followed.

      I started with the "Comms.bas" in the PB examples, and built on from there. But now going back over old code to see how I could make it better. So maybe is a good time to make the code modular and post.

      Will let you know what I come up with
      Engineer's Motto: If it aint broke take it apart and fix it

      "If at 1st you don't succeed... call it version 1.0"

      "Half of Programming is coding"....."The other 90% is DEBUGGING"

      "Document my code????" .... "WHYYY??? do you think they call it CODE? "


      • #4
        Hi Stephane,

        I'm currently writing one that communicates with a largish control panel (used in automation at a furniture factory to control a/c, heating, and dust/fume extraction amongst other things) via RS232. The limitation of using Hyperterminal or a similar general-purpose comms program are:
        - the inability to record the time and date that events happen (the panel does not have a RTC)
        - the inability to control external devices, such as alarm lights / sirens
        - the inability to log data automatically to a disk file or printer

        I'm writing a "hyperterminal replacement" in PB to overcome these limitations, but I'm a relative novice in Windows programming. My coding background is in microcontrollers, and it's discovering the differences that take up the time.

        One issue I'm dealing with now is timers, they seem to be limited to about 10 to 50 milliseconds under Win XP Pro (3 Ghz CPU). I can easily generate sub-microsecond delays (using a timer) in a micro running at a clock speed of 8 Mhz though. This limitation seems rather strange to me...



        • #5
          you can easily get timers to 1ms in Windows. See here for an example:

          Better resolution than that can be a problem.



          • #6
            but I'm a relative novice in Windows programming. My coding background is in microcontrollers.....
            One issue I'm dealing with now is timers..
            Just as a general caution... be aware that using timers in a preemptive multitasking environment (Windows) is not the same thing as using timers in a single-process (MS-DOS or microcontroller) environment.

            Yes, you get your timer notifications or can read one of the system timers, but ONLY when it is your program's "turn" to get some CPU time.....
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]


            • #7
              Obviously, if anything else is running on a PC, it's going to slow things down for other things competing for CPU time.
              However, our app is running on a purpose made PC, with as many processes disabled as possible (No explorer.exe, antivrtus, network, updates, or any other drivers / applications that are not essential for thr PC to perform its task).
              The only startup item is the app (which can't be started in the normal way as explorer has been removed) itself.


              • #8
                Hi Paul,
                I couldn't get that code to work in PBWin, as it was written for PB/CC.
                I've never used CC, and unfortunately don't know enough yet to do the translation.



                • #9
                  I have very little experience in sub Ms timers (heck actually anything less than 0.100 seconds seems "Iffy" to me) but have often wondered if able to do it because of claims of "High Resolution" timers

                  You MIGHHHHHHT be able to use "TIX" and avg the amt of time for a 1ms sleep??? (but even at that its up to an avg, and the cpu)

                  More and more lately I have found and actual use for sub 1/10th of a second reliability, but 1ms or (much less) I have a hard time determining if real, or reliable (or at least till I can see an example showing WHY it is reliable, or only reliable because the sample time is bigger than a guaranteed number of samples)
                  Engineer's Motto: If it aint broke take it apart and fix it

                  "If at 1st you don't succeed... call it version 1.0"

                  "Half of Programming is coding"....."The other 90% is DEBUGGING"

                  "Document my code????" .... "WHYYY??? do you think they call it CODE? "


                  • #10

                    A major difference in writing Windows programs compared to microcontrollers is likely the opportunity to write threaded programs.

                    You might find that your program benifits from having your main functions being taken care of in separate threads as opposed to having to deal with them sequentially (with assosiated timing issues).

                    See the Comms.bas sample program that comes with PB for an example of separating the receive operations from the main program.
                    Rgds, Dave


                    • #11
                      I don't generally use timers for serial communications, but if you want somewhat better resolution, you can use the multimedia timers. It requires that the motherboard have compatible hardware, but that doesn't seem to be a big problem with modern gear.

                      SUB StartMMTimer()
                          %TIME_ONESHOT               = 0     ' Event occurs once, after uDelay milliseconds
                          %TIME_PERIODIC              = 1     ' Event occurs every uDelay milliseconds.
                          %TIME_CALLBACK_FUNCTION     = 0     ' When the timer expires, Windows calls the function pointed to by the
                                                                  ' lpTimeProc parameter.  This is the default.
                          %TIME_CALLBACK_EVENT_SET    = 16    ' When the timer expires, Windows calls theSetEvent function to set the event
                                                              ' pointed to by the lpTimeProc parameter. The dwUser parameter is ignored.
                          %TIME_CALLBACK_EVENT_PULSE  = 32    ' When the timer expires, Windows calls thePulseEvent function to pulse the
                          IF hMMTimer& THEN EXIT SUB
                          hMMTimer = TimeSetEvent ( 1, 1, CODEPTR(MMTimerProc), 0&, %TIME_PERIODIC OR %TIME_CALLBACK_FUNCTION )
                      END SUB
                      SUB MMTimerProc( BYVAL uID AS LONG, BYVAL uMsg AS LONG, _
                                                BYVAL dwUser AS LONG, BYVAL lp1 AS LONG, BYVAL lp2 AS LONG)
                        ' *** If using a periodic MM timer, you should ensure the code you place in the timer callback function
                        ' *** can finish executing before the next MM timer event.
                          ' do something
                      END SUB
                      "There are two novels that can change a bookish fourteen-year old's life: The Lord of the Rings and Atlas Shrugged. One is a childish fantasy that often engenders a lifelong obsession with its unbelievable heroes, leading to an emotionally stunted, socially crippled adulthood, unable to deal with the real world. The other, of course, involves orcs." - John Rogers