Results 1 to 4 of 4

Thread: Comm Ports and VB Can You....HELP!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Holden Beach NC
    Posts
    85
    Help VB Gurus!,

    I am working with a problem that I HOPE can be solved using VB, perhaps using API calls, but the only API code that I use is borrowed, moved to modules and accessed with functions that I understand because the API is way beyond me. Here is a basic outline of the problem:

    A PC on a ship needs to communicate with an MCS system that monitors a large number of sensor inputs around the ship. The current method of doing this uses a form with a mscomm control and a Timer control. The Timer control checks the I/O status (ie sends a request for certain sensor inputs, or Waiting for a response). The mscomm_OnCom event is used to trigger data retrieval and processing. Everything currently works fine until a user begins to drag windows around or do other things that occupy the system for more than 2 seconds (the MCS drops communication after a 2 second timeout limit) and then the monitoring system crashes (or ceases to monitor). The problem seems to be that the VB code is not “High” enough in the system priority list. The obvious answer is to have a computer dedicated to the sensors, but because of space limitations this is not a desirable solution. The ultimate goal of the app is to store real time sensor data in a database, and to allow the user to select which sensors to monitor. The MCS system can accept a request for up to 70 sensors in a block and the communications take around 2ms from request for data to data recieved …. Ok, enough back ground. Four solutions seem viable: 1) Use the API to adjust the priority of the VB app at run time. So that no matter what the user does the Monitoring app receives processing time for at least 2ms out of each second. 2) Write the equivalent of a “TSR” that handles the I/O and keeps the MCS connection open and either places the data in the database or holds it in a buffer that the App can access. 3)Use "C" to write an interface. (I have NO experience with C, but understand that it allows a great deal more control over the OS than VB.) 4) Find or Develop an interface card that will allow communication with the MCS to remain open and communicate with the program in a less time critical manner. (Least desirable solution).

    Any help and/or suggestions on how to accomplish the goal would be greatly appreciated. I find myself in way over my head. I hate it when everything works except when the client goes to use it, and then he does things that weren't part of the description!

    Thanks,

    Hunter

    ps. There is a similar post in the API forum. In case any one else is interested in this sort of problem I will post replies here if there are any viable solutions posted there and vice versa. Thanks again!

  2. #2
    Guest
    Hmm, 2 second timeout is a bit swift! Must be a good reason for it though, maybe it is possible to extend this timeout somehow. If not, then maybe you could get another PC to run as a dedicated interface, so that the timeout would never be reached, but connect it to the main PC so the technical stuff can be done by your program. Its a bit of a messy solution but its a tricky question.

    Otherwise, you could turn off everything that takes up surplus clock-cycles, for example: Background wallpaper, complex screensavers etc, and turn off "show windows contents while dragging". Stuff like that may help to prolong the longevity of the system integrity.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Holden Beach NC
    Posts
    85
    Originally posted by wossname
    Hmm, 2 second timeout is a bit swift! Must be a good reason for it though, maybe it is possible to extend this timeout somehow. If not, then maybe you could get another PC to run as a dedicated interface, so that the timeout would never be reached, but connect it to the main PC so the technical stuff can be done by your program. Its a bit of a messy solution but its a tricky question.

    Otherwise, you could turn off everything that takes up surplus clock-cycles, for example: Background wallpaper, complex screensavers etc, and turn off "show windows contents while dragging". Stuff like that may help to prolong the longevity of the system integrity.
    Yes,

    that would be the problem that I was presented with....write a program that works. Well I have acheived that. Now they want the PC to be available for other things too. As I stated the problem is that they want this PC to be available for other tasks, and these other tasks need to take a back seat to the main task. Crazy, but it is the problem. Thankyou for resonding, and, just for the record, I agree with you.

    Hunter

  4. #4
    Guest
    I found an example for changin the Process Priority

    Code:
    Const THREAD_BASE_PRIORITY_IDLE = -15
    Const THREAD_BASE_PRIORITY_LOWRT = 15
    Const THREAD_BASE_PRIORITY_MIN = -2
    Const THREAD_BASE_PRIORITY_MAX = 2
    Const THREAD_PRIORITY_LOWEST = THREAD_BASE_PRIORITY_MIN
    Const THREAD_PRIORITY_HIGHEST = THREAD_BASE_PRIORITY_MAX
    Const THREAD_PRIORITY_BELOW_NORMAL = (THREAD_PRIORITY_LOWEST + 1)
    Const THREAD_PRIORITY_ABOVE_NORMAL = (THREAD_PRIORITY_HIGHEST - 1)
    Const THREAD_PRIORITY_IDLE = THREAD_BASE_PRIORITY_IDLE
    Const THREAD_PRIORITY_NORMAL = 0
    Const THREAD_PRIORITY_TIME_CRITICAL = THREAD_BASE_PRIORITY_LOWRT
    Const HIGH_PRIORITY_CLASS = &H80
    Const IDLE_PRIORITY_CLASS = &H40
    Const NORMAL_PRIORITY_CLASS = &H20
    Const REALTIME_PRIORITY_CLASS = &H100
    Private Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As Long, ByVal nPriority As Long) As Long
    Private Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
    Private Declare Function GetThreadPriority Lib "kernel32" (ByVal hThread As Long) As Long
    Private Declare Function GetPriorityClass Lib "kernel32" (ByVal hProcess As Long) As Long
    Private Declare Function GetCurrentThread Lib "kernel32" () As Long
    Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    Private Sub Form_Load()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim hThread As Long, hProcess As Long
        'retrieve the current thread and process
        hThread = GetCurrentThread
        hProcess = GetCurrentProcess
        'set the new thread priority to "lowest"
        SetThreadPriority hThread, THREAD_PRIORITY_LOWEST
        'set the new priority class to "idle"
        SetPriorityClass hProcess, IDLE_PRIORITY_CLASS
        'print some results
        Me.AutoRedraw = True
        Me.Print "Current Thread Priority:" + Str$(GetThreadPriority(hThread))
        Me.Print "Current Priority Class:" + Str$(GetPriorityClass(hProcess))
    End Sub
    I hope you can use it.
    If you can use it you can have from me a control to change your App to a NT- Service with Event Logging.
    If yes then send me a EMail to [email protected] and i'll send you the control with a sample back

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