Using Nokia AT command in VB 2010 - vb.net

I am a beginner in learning AT commands and windows programming.
I prepared a code just to read the Serial no of a Nokia phone in VB 2010 as
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.Open()
SerialPort1.WriteLine("AT")
SerialPort1.WriteLine("AT+CNUM")
TextBox1.Text = SerialPort1.ReadLine()
SerialPort1.Close()
End Sub
End Class
Unfortunately, it is not working, no error message.
Port I selected is COM which I verified through device manager. Baud rate set as 9600.
If anybody can help, Please.......
Thanks

0) open read before write,
try switch:
SerialPort1.Open()
TextBox1.Text = SerialPort1.ReadLine()
SerialPort1.WriteLine("AT")
SerialPort1.WriteLine("AT+CNUM")
SerialPort1.Close()
1) send \r (\r\n) -- end of string
2) use command with view resultats:
call (ATD<number>);
busy (ATH);
response call (ATA) -- for view this 2 commands to call from phone to modem;
other (blink/switch off radio/play tone)
disclaimer:
VB don't know, i'm using python on Linux;
sorry for my dirty english.

Related

Windows Media Player VB.net

I have a WMP in my vb.net project and I wanted to load the next media automatically after the first is finnished I did some research on googel and found the simple to understand code as per below.
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped Then
AxWindowsMediaPlayer1.URL = ("Test2.mp4")
MessageBox.Show("Playing End")
End If
End Sub
I however cant get it to automatically play the next (Test2.mp4) unless I have the messagebox pop-up. I discovered this purely by accident. However I dont want the Messagebox to pop-up everytime a new Mp4 file is ready to be played. Dose anybody know what is going on here and how I can fix this?
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim oTask01 As Threading.Thread
oTask01 = New Threading.Thread(AddressOf oStarting01)
oTask01.Start()
Dim omessagebox As MessageBox = Nothing
omessagebox.Show("Playing End", "", MessageBoxButtons.OK)
oTask01.Abort()
End Sub
Private Function oStarting01() As Byte
While True
System.Windows.Forms.SendKeys.SendWait(vbCr)
End While
Return 0
End Function
End Class
Hi, try with this code. It works. Diving more deeply in Windows system and subsystems is not an easy task, not at least for me. I hope you get what you were looking for for your software. Thank you very much. Happy codding!. :)
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As
System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent)
Handles AxWindowsMediaPlayer1.PlayStateChange
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped Then
AxWindowsMediaPlayer1.URL = ("Test2.mp4")
'MessageBox.Show("Playing End") 'This line was commented because is not neccesary in this fragment of code
End If
End Sub
Hi, if I have understood well to you, you wanted to supress the message box. It is got doing a comment's line with "'". I hope you like it and continue enjoying with computers and software. Thank you very much and happy codding. :)

Brother Printer Visual Basic 10

Hello everyone and thank you for being such great and helpful community. I am currently working on Visual Basic App (using 10 express version) to print labels by using Brother Printer QL-500. For some reason samples provided by Brother don't work.... any of them and worst part there is no Errors any kind.... now Brother P-Touch Editor 5.1 works and prints fine. I am using b-PAC3 Client Component(64 Bit), running on Windows 7 64 bit. I know some people suggested to target x86 and I did that with no luck its a same thing nothing is happening please see Brother Code I am using below. Thanks!
b-PAC 3.0 Component Sample (Badge)
'
' (C)Copyright Brother Industries, Ltd. 2009
'
'*******************************************************************
Option Explicit On
Public Class Badge
Const sPath = "C:\Program Files\Brother bPAC3 SDK\Templates\Badge.lbx"
'********************************************************
' Open and Print a spcified file.
'********************************************************
Public Sub DoPrint()
Dim bRet As Boolean
Dim ObjDoc As bpac.Document
ObjDoc = CreateObject("bpac.Document")
'Open lbx file
bRet = ObjDoc.Open(sPath)
If (bRet <> False) Then
ObjDoc.GetObject("objName").Text = txtName.Text
ObjDoc.GetObject("objCompany").Text = txtCompany.Text
'objDoc.SetMediaByName(objDoc.Printer.GetMediaName, True)
ObjDoc.StartPrint("", bpac.PrintOptionConstants.bpoDefault)
ObjDoc.PrintOut(1, bpac.PrintOptionConstants.bpoDefault)
ObjDoc.EndPrint()
ObjDoc.Close()
End If
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
DoPrint()
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
End Class
After trying to contact Brother technical for 2 weeks resolved nothing still waiting for their response but everything is working now... Not this Badge code but my program if anyone has same issue try installing b-PAC3 Client Component non 64 as well and re-install brother drivers somehow this fixes the issue still wonder what is the problem would be nice to know to avoid it on other systems.

Communicating with SAG105 METTLER TOLEDO using Cable LC-RS9 RS232 9 pin for IBM PCXT in VB.net

I'm trying to code in VB.net a SAG105 METTLER TOLEDO that is connected to a pc using the Cable LC-RS9 RS232 9 pin for IBM PCXT. I have researched on the internet but was unable to find a template code that can assist me to send data to the weighting scale device using VB.net. I had a look at the code for serial port, but as this is a RS-232 for IBM PCXT, this serial port method didn't work. I had contacted the company as I didn't have any documentation for scale, unfortunately they said they don't have any template code for the device.
Could someone please help me to get started on opening the communication channel and sending the basic commands by guiding me to the right website or sharing some of your knowledge. I have spend days already on this and have gone no where with it.
Many thanks in advance
I managed to find a decent code for VB that works, however I'm having some problems. So the commands that I will use are "Z" - setting the scale to zero, "SIR" read unstable value continually, "S" getting stable value, "SI" - read unstable value once.
However, the problem I'm having is that the routine to send command runs once, but the receive command runs twice. When it runs the first time I get the correct value but second time I get ES (means syntax error the balance didn't recognize the command). I put some breaks in the see this.
My code is :
Dim myWeight As String, myWeightValue As Single
Delegate Sub SerialDataIn()
Public myDelegate As SerialDataIn
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
CloseSerialPort() ' Close the port
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'This opens the serial Port
OpenSerialPort()
'Assign the delegate for the Serial Communications handling
myDelegate = New SerialDataIn(AddressOf SerialDataInProc)
End Sub
'HANDLE SERIAL PORT COMMUNICATIONS IN TO THE PC FROM THE BALANCE:
Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
'Get the weight value string from the balance
myWeight = SerialPort1.ReadLine
'Call a new Thread Procedure
Me.Invoke(myDelegate)
End Sub
'The delegate...
Sub SerialDataInProc()
'Display the received string in the text box
Me.TextBox1.Text = myWeight
'If any string is received that is not prefixed with an 'S' then it is not a weight value, so don't try to process the value
If myWeight.Substring(0, 1) <> "S" Then GoTo HopIt
'Convert the string received from the balance into a value
myWeightValue = Convert.ToSingle(myWeight.Substring(4, 10))
'If the weight on the balance exceeds 50g then reset the balance (stop data transmission) and display the message "Stopped"
If myWeightValue > 50 Then
SerialPortOut("#")
MsgBox("Stopped")
End If
HopIt:
End Sub
'Write any command to the balance port
Sub SerialPortOut(ByVal myText)
Try
SerialPort1.WriteLine(myText & vbCrLf)
Catch ex As Exception
MsgBox("Transmission to Serial Port Failed. Error: " & Err.Description, MsgBoxStyle.Critical, "Comms Failed")
End Try
End Sub
'Send the Balance the SIR Command (Send current weight value and repeat) if the [SEND SIR] button has been pressed
'Send the # Command to the balance (Cancels all previous commands, so resets the balance and stops data transmission) if the [Send #] button is clicked
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonReset.Click, ButtonStart.Click
Select Case sender.name
Case Is = "ButtonReset"
SerialPortOut("#")
Case Is = "ButtonStart"
SerialPortOut("S")
End Select
End Sub
'Set the serial Port Parameters and open the Port
Private Sub OpenSerialPort()
With SerialPort1
.PortName = "Com1"
.BaudRate = 9600
.DataBits = 8
.Parity = IO.Ports.Parity.None
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.XOnXOff
Try
.Open()
Catch ex As Exception
MsgBox("Could not open the Serial Port! Error: " & Err.Description, MsgBoxStyle.Critical, "Port Error")
End Try
End With
End Sub
'Close the Serial Port
Private Sub CloseSerialPort()
SerialPort1.Close()
End Sub
lease can someone have a look at this and tell why the above described problem is occurring
The protocol for the SAG105 seems to be the MT-SICS Standard Interface Command Set
Using our Docklight software (even with the free evaluation) you can easily try this out on a "modern" PC with a standard USB-to-RS232 plug.
It seems the protocol consists of very simple text commands, so sending the following text command to the SAG105 should return a current balance value:
I2<CR><LF>
with "CR" = carriage return, ASCII decimal code 13. And "LF" = Line Feed, ASCII decimal code 10.
I couldn't locate the standard COM parameters (e.g 9600 baud, 8 data bits, 1 stop bit, no parity) for the SAGE105, but maybe you have this information already and this could be anyhow set to an application-specific setting by your old application. If you know the RS232 settings, I could actually send you a small example project for Docklight to manually talk to the SAG105.
Within .NET such text based simple protocols should be straightforward to implement, once you have confirmed the settings and the protocol commands you are using are correct.

Sending SMS via USB GSM Modem

I am trying to develop a module to send SMS from my application. The problem is that when I send an AT Command to a connected cell phone, my app stops responding. I'm using a Nokia 6720C and I have installed Pc Suite. It also appears in the Com Ports.
My code is below. What am I doing wrong?
Imports System
Imports System.IO.Ports
Imports System.Threading
Imports System.ComponentModel
Public Class Form1
Delegate Sub SetTextCallback(ByVal [text] As String)
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
With SerialPort1
.PortName = "COM14"
.DataBits = 8
.Parity = IO.Ports.Parity.None
.StopBits = StopBits.One
End With
SerialPort1.Open()
SerialPort1.Write("AT" & vbCr)
SerialPort1.Close()
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting())
End Sub
Private Sub ReceivedText(ByVal [text] As String)
'compares the ID of the creating Thread to the ID of the calling Thread
If Me.TxtResponse.InvokeRequired Then
Dim x As New SetTextCallback(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
Me.TxtResponse.Text &= [text]
End If
End Sub
Well, at the end of the AT command you must add Chr(13) and Chr(10), you used Chr(13) only (which is "vbCr"), try replacing it with vbCrLf (Carriage-Return "Chr(13)" and Line Feed "Chr(10)"). I think this is the problem (the command string is not complete).
If the problem still resides, try the following to test your work:
Try using your VB.NET code to communicate with a GSM modem (not your phone). If it works fine, then maybe the phone does not accept AT commands.
Try using a terminal program to send the AT command to the phone. The terminal program can be like "Hyper Terminal" or "Maestro Smart Terminal" (you can search for it on google).
I hope this was helpful, good luck.

Monitor process standard output that does not necessarily use CR/LF

My application periodically starts console programs with process.start. I need to monitor the output of the programs in "realtime".
For example, the program writes the following text to the console:
Processing.................
Every second or so a new dot appears to let the user know the program is still processing. However,... until the programm outputs a CR/LF, I am not able to retrieve the standard output of the program (while it is still running).
What can I do to get the output in realtime for - let's say - piping it into a database for instance in VB.NET?
what about sending output into a text file and reading that file every second?
I'm gutted since I did have a prototype application at home that did something like this. I'll see if I can fetch it. In the meantime have a look at this link:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx
It shows how to redirect the output of applications to a custom stream e.g.
Public Class Form1
Private _p As Process
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim psi As New ProcessStartInfo()
psi.FileName = "C:\mydir.bat"
psi.RedirectStandardOutput = True
psi.UseShellExecute = False
_p = New Process()
_p.Start(psi)
tmrReadConsole.Enabled = True
End Sub
Private Sub tmrReadConsole_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrReadConsole.Tick
If _p IsNot Nothing Then
txtConsoleOutput.Text = _p.StandardOutput.ReadToEnd()
End If
End Sub
End Class
The above is a webform that has a timer which is used to poll the output stream of a console and get it's content into a textbox. It doesn't quite work (hence why I want to find my other app), but you get the idea.
Hope this helps.