SHELLCMD question

Previous topic - Next topic

Gary

Apologies in advance for taking this a little off topic further on.

I have a program that uses the serial port for comms with another board and have found that unless I initialise the comms port with another program first GLB does not seem to be opening it up correctly (Im using Gernots Serial wrapper). So I have constructed a small program in VB that just opens the port.

Code (glbasic) Select
Module Module1

    Sub Main()
        SendSerialData("hello")
    End Sub
    Sub SendSerialData(ByVal data As String)
        ' Send strings to a serial port.
        Try
            Using com1 As IO.Ports.SerialPort =
                My.Computer.Ports.OpenSerialPort("COM1")
                com1.WriteLine(data)
            End Using
        Catch e As System.IO.IOException
            Console.WriteLine("port not open", e)
        End Try
    End Sub

End Module


which opens the port if it is present or gives a port not open message in the console if it is not present.

My problem is when I call the command with SHELLCMD using the following code

Code (glbasic) Select
GLOBAL commsflag,rv

commsflag = SHELLCMD("opencom4.exe",TRUE,TRUE,rv)

DEBUG commsflag+"\n"
DEBUG rv+"\n"


commsflag is always set to 1 indicating the program exited ok (I presume) and rv is always 0. Are there any VB gurus who could tell me how to get the console program to return a value indicating the status of the port that rv can then read? Or is there a way I can get GLB to detect there has been text in the opened console window and use that as an indication of the error?

I have already worked out another way round the problem but its messy and involves cycling the serial ports, sending data and looking for a response. If I cant get a quick fix to the above I will use this method

Thanks
Gary

Kitty Hello


Gary

vb 2010

but found an example that gave the info needed. Many thanks again

Gary

#3
any way of forcing the focus back to a full screen GLBasic program after it has run a dos program? I used AUTOPAUSE FALSE to keep the programm running but until the screen is clicked and focus given back to the GL program the windows task bar is still visible

Kitty Hello

sounds like a bug.

Slydog

I'm not sure what parameters the GLBasic 'SHELLCMD()' uses (if it indeed uses the Windows API for shelling).
But there are tons of focus parameters for the Win32 shell command: ShellExecute

Check out these resources:
http://msdn.microsoft.com/en-us/library/bb762153%28v=vs.85%29.aspx
http://allapi.mentalis.org/apilist/ShellExecute.shtml

You could program your own shell command using this api call, you just need to wrap the dll call properly.
Check other DLL wrapped functions in the forum for examples on how to do this.

If this doesn't work, and you still have the taskbar on top, you could try other api window commands.
Get the shell vb program to set focus to the GLBasic window when it exits.
You may have to look up the handle of the GLBasic window using other API commands, it gets complicated.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Kitty Hello

GLBASIC_HWND() is the main hwnd. You can use that inline with SetFocus.
I'll try to fix it.

Gary

cheers Kitty

I have just set the taskbar to never be on top and auto hide for now. It works but if a sound is played before you give focus back to the program it doesnt sound and when focus is given back to the program it defaults the volume to 1 and takes a few plays of sounds to settle back down which is strange