Control of Serial Port

Discussion in 'Questions (Windows Mobile)' started by DrStrangeLv, Dec 11, 2008.

  1. DrStrangeLv

    DrStrangeLv Member Licensed User

    See script below

    What I'm having problems with is getting the port to open and close.

    Within the loop I need to be able to open port , keep it open for a set time
    then close the port.
    Re-cal to open port time
    and then re-do the loop process.

    I "noob" at this and very sure I've done something wrong.

    What does happen is it open the port once , goes through the loop and at end of loop closes port.

    Thank you to any who can assist.

    Sub Globals
    'Declare the global variables here.

    Dim EVtemp
    Dim FinalEV
    Dim intDelay
    Dim Shoot
    Dim Total_Exposures
    Total_Exposures = 0
    Dim Expos_Begin_Counter
    Dim Begin_Exposure_Speed
    Dim Current
    Current = " "
    Shot_Count = 0
    tempcount = 0

    Dim ex
    Dim dly
    Dim nm
    Dim dm
    Dim nev
    Dim Minutes_Between_Shots

    End Sub

    Sub App_Start
    '***serial.New2 (1,9600,"N",8,1)

    End Sub

    Sub Button1_Click
    Current.Text = " "
    serial.PortOpen = True
    Shot_Count = 0
    Dim ex
    Dim dly
    Dim nm
    Dim dm
    Dim nev
    Minutes_Between_Shots = (Minutes.Text * 60 )*1000 Total_Exposures = ex

    ' ***Do Math Below***
    Expos_Begin_Counter = ((ex - 1)/2)
    EVtemp = nev
    SHUTTER_METERED = nm / dm
    If EVtemp * 2 <= 1 Then
    FinalEV = (EVtemp + 1)*2
    FinalEV = Evtemp * 2
    End If

    If SHUTTER_METERED < 1 Then '***Test for Whole Seconds***

    Begin_Exposure_Speed = dm

    Do While Expos_Begin_Counter > 0 '***Do Fraction Routine here***
    Begin_Exposure_Speed = Begin_Exposure_Speed / FinalEV

    Expos_Begin_Counter = Expos_Begin_Counter - 1 Loop

    ' ***Do Suhtter Routine Below***
    This_Exposure = Begin_Exposure_Speed

    Shot_Count = 1

    Computed_Time = 1 / This_Exposure

    '***Loop for port open close
    Do While Shot_Count <= Total_Exposures
    Sleep((dly * 1000))

    serial.DTREnable = True '***open port date send
    Sleep(Computed_Time * 1000) '***hold port open for time
    serial.DTREnable = False '***close port

    '***re-cal time and bump up loop count
    This_Exposure = This_Exposure * 2
    Computed_Time = 1 / This_Exposure
    Shot_Count = Shot_Count + 1

    '***If Whole Seconds do whole second routine***

    End If
    Sleep((dly * 1000))
    Current.Text = "Done"
    serial.PortOpen = False
    End Sub
  2. Softselect

    Softselect Member Licensed User

    Here is a copy of my commented test program for the serial port
    Hope it helps

    Attached Files:

  3. Zenerdiode

    Zenerdiode Active Member Licensed User

    I'm guessing your shutter is opening as soon as the program is run? If so, its because as soon as the Port is opened; the DTR line will be high.

    Choose which pin you are going to use as the shutter control pin. I suggest DTR. Remember that according to the hardware of the serial port you use, when the DTR line is asserted it will be at a positive voltage and when disabled it could be the same magnitude but negative, 0V or anything else. You really need to check with a multimeter as to what your PDA is giving out. Do a simple app with say, a checkbox to check what is going on with your port. (I found with mine, when asserted it gave +6.5V and when disabled -6.5V. I use mine with a signal diode and drive an instrumentation relay to provide a 'volt free contact' to interface to whatever I like.)

    To get around the DTR being high when the port is opened, in your App_Start;

    Sub App_Start
    Serial.DTREnable=False 'These have to come
       Serial.RTSEnable=False 'before PortOpen=True
    End Sub

    'In subsequent Subs, set DTR to True and False as required.
    Also, it may just be peculiar to my PDA, but I found I locked everything up once because the Serial Port didn't close properly. It doesn't harm to add:

    Sub Shooter_Close
    End Sub
    **DO NOT** use PortOpen to control your shutter, leave it open and control your chosen line, (eg DTR)
    Last edited: Dec 12, 2008
  4. DrStrangeLv

    DrStrangeLv Member Licensed User

    This explains a great deal of whats been happening.
    The manual does not describe serial use to well but both of you have made things much clearer.

    Many thanks

  5. mjcoon

    mjcoon Well-Known Member Licensed User

    Hi Friedrich, I thought your program might help me to find out what is happening with a 3rd-party program I have tried.

    But when I tried to run your SBP on my device I got a "native exception" in B4PPC and details:
    ExceptionCode: 0xc0000005
    ExceptionAddress: 0x01258fc8
    Reading: 0x00000004

    I don't suppose this means anything to you (unless you happened tohave seen it yourself) so I will have to ask a B4PPC expert...

    Cheers, Mike.
  6. Softselect

    Softselect Member Licensed User

    Hi Mike,
    I am by no means an expert, but the program i wrote was for the desktop not the device, you will have to change the dll's for the device
    unfortunately I dont have a device with me so i cant test it, but when i get back home in a weeks time i can try it for you, but i am sure you would have come right by then:)
    thanks Friedrich

    Sorry Mike I am talking straw, the device was an HP with serial port, my confusion is that i normaly only use com on the desktop, i will find the last program for the device that I used an post it later
    Thanks Friedrich
    Last edited: Mar 30, 2009
  7. Softselect

    Softselect Member Licensed User

    hi mike,
    try this copy, it has DBCOMM.dll added, it may solve your problem
    under tools, add components, add dll
    thanks Friedrich

    Attached Files:

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice