Windows CE Generate Log on Barcode Scan - vb.net

At the moment, I am currently faced with a small project as to update a current bar-code system so that it will store a log file on scan. However, I'm not provided with any source code for the current system. So I was thinking maybe I can develop a small .exe to run and it's job is just to store the ID scanned as well as the current timestamp to a text file named log.txt.
Here's all I'm provided with:
A small touchscreen device running on windows CE with a built-in bar-code
scanner (imager) and few other ports including a USB port.
A memory stick containing the object codes (exe, dll, pdb, bat and
xml) and other multimedia files.
SDK CD containing an SDK platform installer (.msi) requiring VS2005
SP1 to be installed.
Now I'm just confused on how to get the job done. I've been spending the past 3 days researching about this. One of my Google findings suggest that the bar-code scanner works just like a keyboard input? Hence, I made a simple VB6 application with a textbox to store the contents of it and reset the textbox at the same time when a 10-digit ID is inputted. The application is not executable in the device though (I found out that VB6 exe is not executable in winCE, sadly).
Furthermore, I tried to open MS WordPad in the device and attempted to scan the bar-code. Nothing is copied to the WordPad though. I thought bar-code scanner works identically like a keyboard input? My mistake? Any clarification will be highly appreciated.
I'm actually new to bar-code and winCE development and if it helps, I'm familiar with the following languages (in-order): C#, VB6, VB.Net, C, Java. Any suggestion on the quickest way to get the job done? I believe it's not a hectic job, but I'm stuck on where to begin.
Just tell me in case any further clarification is needed. Thanks in advance!
Edit#1:
Here's what I tried so far (Assuming Barcode Scan works just like keyboard input):
(Using VB.Net for Windows CE 5.0 Device under VS2005)
Private Sub barcodeTB_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles barcodeTB.TextChanged
If (Len(barcodeTB.Text) = 10) Then 'If 10 digits ID have been scanned..
Using writer As IO.StreamWriter = New IO.StreamWriter("log.txt", True)
writer.WriteLine(barcodeTB.Text & " " & DateTime.Now)
End Using
barcodeTB.Text = "" 'reset TextBox
End If
End Sub
It works just fine when I input the code manually. But nil when I tried to scan my bar-code.
Edit#2:
There are several PDFs provided in their website: http://www.scantech-id.com/en/support/download.php?pin=42676d021abeff1e479180ffeb4240e5
I'm perfectly sure that the scanner is installed in COM3 port if it helps! Still trying to figure this out.
Edit#3:
So this is my last attempt: To read it directly via the DataReceived from COM3 Port.
I set a timer so that it sends the data transmitted every 1 second if there's any. It works nicely as the textbox only get updated when I scan my bar-code. However, the output is not in a desirable format. What am I doing wrong? See below:
And here's the code:
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
Handles SerialPort1.DataReceived
Q.Enqueue(SerialPort1.ReadExisting())
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
SyncLock Q
While Q.Count > 0
receivedTB.Text &= Chr(13) & Chr(10) & Q.Dequeue
End While
End SyncLock
End Sub

Related

Setting the value of a variable in Visual BASIC

Hi i'm new in programming world and I've started my programming by Visual BASIC. I'm trying to set a value of a variable through the program closing event and load the same value in program load event. As example:
At first I tried:
Dim Age as Integer
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Age = 50
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Textbox1.text = Age
End Sub
But when I close the program and restart it, it resets to zero.
Next I tried "Settings" from properties but if I move my program from one location to another then it also resets everything.
Finally I tried Stream readers and writers to catch the final value but for this I had to attach some text files to the programs which I don't want. Can anyone help me how to solve the following problem with custom class libraries or by something else?
All the variables that you have are run time variables. What that means is it will only have value till your program is running.
If you want to store the data taken from user, you store it in database. You can use any kind of database and connect it to your program, store everything in there. You can also retrieve the values from database to use in system when you restart your program.
If you are new to programming and trying to learn visual basic, start with basic concepts or pick up a book that start with basics. Once you know the basics of programming, you can read about connecting program to database.
The value of age is never going to remain static when the application is shut down unless you keep it in the application settings or some sort of flat file, database etc. The initial value could be set in the application when the form opens or from at static value in application settings, but unless you store the value somewhere other than memory, it will not persist.
What you can do is create a form called module1.vb . in this form declare and set your variables . . .
Example
Public Age As Integer = 50

How do you launch an .exe in a VB.net application who's directory varies amongst users?

I am creating an application for an Arma 3 server that directly launches the game and connects the user to a specific server. The problem that I am encountering, being the relatively new VB coder that I am, is that the Arma3battleye.exe directory (the .exe used to launch the game) may be installed in different directories depending on where the user originally installed it. I've developed the code to connect the user to the server if they've installed Arma in the normal location:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Process.Start("C:\Program Files (x86)\Steam\steamapps\common\Arma 3\arma3battleye.exe", "2 1 -noSplash -skipIntro -useBE -noPause -world=empty -connect=192.99.36.80 -port=2505 -mod=#Exile;#AlRayak;#AllInArmaTerrainPack;#CUP Units;#CUP Vehicles;#CUP Weapons;#CBA_A3;#TRYK's Multi-Play Unifrom's pack")
End Sub
However, after researching for many hours, I cannot determine how to have the program automatically determine the install directory of the arma3batteye.exe and then execute it with all of the correct start parameters included. Any solutions or pointers to help solve this problem would be greatly appreciate.
TLDR: What is the easiest way to program an application to automatically find the install directory of a given .exe and then execute it with the given parameters as I've done above?
Edit: Another thread similar to mine asks a similar question (how to view/get to the steam folder without hard coding it. They arrive at the conclusion that if you do (for winx32):
Dim strSteamInstallPath as String = My.Computer.Registry.GetValue(
"HKEY_LOCAL_MACHINE\SOFTWARE\Valve\Steam", "InstallPath", Nothing)
Or using this registry location for winx64:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Valve\Steam
and then were to create a button using Process.Start that it would allow you to ultimately view the directory. At this point I haven't discovered a way for that to translate into being able to execute the battleyearma3.exe from within that steam directory with the proper parameters. While it seems this code may be useful in arriving at the solution I'm looking for, I can only get the program to view the general steam directory at this time.
edit: Solution posted at bottom. Thanks to #VisualVincent who was really the one that allowed me to complete this. It really should be you having posted the correct answer, not me.
I would use the registry...
You add a key like HKEY_LOCAL_MACHINE\Software\Arma3\ServerPath = "..." when you install the server.
And whenever you need to start the client, you check up the path from that registry key.
So with the comments and tips you gave me (especially #VisualVincent) I managed to piece enough stuff together to solve my issue. Thanks to everyone for the help:
First I declared 2 variables. The first one (BattleyePath) goes into the registry as far as I can get it to dig. Executing this variable on its own will open the users steam directory. I then declared a second variable (BattleyePath2) which uses IO.Path.Combine get to the directory the users Arma3.exe is installed in:
Dim BattleyePath As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Valve\Steam", "InstallPath", Nothing)
Dim BattleyePath2 As String = IO.Path.Combine(BattleyePath, "SteamApps", "common", "Arma 3", "arma3battleye.exe")
I added a couple buttons to close the program and mute the sound:
`Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
My.Computer.Audio.Stop()
End Sub`
Finally I created the button that actually launches the game:
`Private Sub Button4_Click_1(sender As Object, e As EventArgs) Handles Button4.Click
Process.Start(BattleyePath2, "2 1 -noSplash -skipIntro -useBE -noPause -world=empty -connect=192.99.36.80 -port=2505 -mod=#Exile;#AlRayak;#AllInArmaTerrainPack;#CUP Units;#CUP Vehicles;#CUP Weapons;#CBA_A3;#TRYK's Multi-Play Unifrom's pack")
End Sub`

How to save a changed label when you exit

In my program I have a preview, and edit side.
When you edit using the text boxes on the edit side(right side) and click "save", It should change the label on the right side (preview side). Although when you exit the program and re-open, all the data you entered has disappeared!,
I have tried the below code and had no luck as my result.
Public Class Form1
Private Shared NameBasic As Integer
Public Sub New()
InitializeComponent()
lblNameBasic.Text = Convert.ToString(NameBasic)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
NameBasic = txtFirstBasic.Text
lblNameBasic.Text = Convert.ToString(NameBasic)
End Sub
End Class
Also my goal is to have it be able to take it on a flashdrive onto any computer and have that data still saved within the exe. Is this even manageable? (I am more of a web based programmer so I am a bit new to this)
You need to write values to a text file at the same location of the exe. and read it. you will need both exe and the textfile.
OR
You will need to write a dll on run-time and write some values while closing the application. this will be more secure then the text file. here you will need both exe and dll to be copied into flash drive
OR
the application setting as spoken by others..

Copy File on Modification FIleSystemWatcher, Visual Basic (VS 2012 V11)

After looking through many sites and some tutorial videos, I'm still stumped on this one. I'm finishing up a program and I need to add one last bit of functionality.
The program works this way. The user specifies a file in textbox1 and then specifies a directory in textbox2. The user sets how often they want the file to by copied in textbox3. The user hits run and the program copies the file to the new location, adding a number to the file name each time it is copied (to avoid overwrites). That all works fine, but I want the user to have the choice to either copy the file by time or when the file is modified.
How can I use the FileSystemWatcher to look for modification in the directory (given in textbox1) and then call the statement that copies the specified directory to the target destination (specified in textbox 2)?
Additional Note:
In one tutorial the FileSystemWatcher path was set up by doing this
Dim watched As String = System.IO.Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "Pictures")
Dim fsw As New FileSystemWatcher(watched)
The path that the code directs to is "C:\Users[User Name]\Pictures" .
I can't find a resource online that shows what variables ".GetEnvironmentVariable" accepts or even what the variables mean. This is one of many reasons why I am having trouble with this last bit code.
GetEnvironmentVariable returns the value for the specified environment for the current process.
In the case of your example, USERPROFILE is the path to the folder for the current user. For example, on my laptop USERPROFILE is C:\Users\Tim.
The output of System.IO.Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "Pictures") would be the USERPROFILE path plus "Pictures" - to continue with my example, it would be C:\Users\Tim\Pictures - which is the physical path to the My Pictures folder for my user account.
To get a list of all your environment variables, if you're curious, go to the DOS prompt and type in SET and hit return.
To answer your original question, you need to handle the FileSystemWatcher.Changed Event.
For example:
Private Shared Sub OnChanged(source As Object, e As RenamedEventArgs)
' Do your copy here
End Sub
You can hook the event handler up to your FileWatcher like this:
AddHandler fsw.Changed, AddressOf OnChanged
However, pay attention to this warning from the MSDN docs.
Common file system operations might raise more than one event. For example, when a file is moved from one directory to another, several OnChanged and some OnCreated and OnDeleted events might be raised. Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. Likewise, some applications (for example, antivirus software) might cause additional file system events that are detected by FileSystemWatcher.
This is the code I used it does what I want it to.
Option Explicit On
Option Strict On
Imports System.IO
Imports Microsoft.VisualBasic ' I don't know this one, but the code worked without this.
Imports System.Security.Permissions ' I don't know the exactly what this does but the
' http://msdn.microsoft.com/ site did this, I assume it'f to allow for permission to
' watch files? The code still worked for me without this
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
Dim directoryPath As String = Path.GetDirectoryName(TextBox1.Text)
Dim varFileSystemWatcher As New FileSystemWatcher()
varFileSystemWatcher.Path = directoryPath
varFileSystemWatcher.NotifyFilter = (NotifyFilters.LastWrite)
varFileSystemWatcher.Filter = Path.GetFileName(TextBox1.Text) ' I know this
' limits what's being watched to one file, but right now this is
' what I want the program to do.
AddHandler varFileSystemWatcher.Changed, AddressOf OnChanged
varFileSystemWatcher.EnableRaisingEvents = True
End Sub
Private Sub OnChanged(source As Object, ByVal e As FileSystemEventArgs)
My.Computer.FileSystem.CopyFile(e.FullPath, TextBox2.Text & "\" & e.Name, True)
End Sub

No output in using wav file input with Microsoft SAPI 5.4 Api

I am working on a project where i need to use speech recognition to convert a wav file input speech ( conversation ) to text. After trying CMUSPhinx for a while, with terrible results, i am considering using Microsoft SAPI (Speech API) 5.4
I am coding as a Visual basic windows application from visual studio. Here is my code snippet :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Dim SAPI
' SAPI = CreateObject("sapi.spvoice")
' SAPI.Speak(TextBox1.Text)
' Create new recognizer
Dim Recognizer As New SpInprocRecognizer
' create input file stream
InputFile = New SpFileStream
' Defaults to open for read-only, and DoEvents false
InputFile.Open(MY_WAVE_AUDIO_FILENAME)
' connect wav audio input to speech recognition engine
Recognizer.AudioInputStream = InputFile
' create recognition context
RecoContext = Recognizer.CreateRecoContext
' AddHandler RecoContext.Recognition, AddressOf RecoContext_Recognition
' create grammar
Grammar = RecoContext.CreateGrammar
' ... and load dictation
Grammar.DictationLoad()
' start dictating
Grammar.DictationSetState(SGDSActive)
End Sub
In the MY_WAVE_AUDIO_FILENAME, i have given the filename with full path. When i run this code on click of the button, i dont get any output. I have used the following recognition method :
Private Sub RecoContext_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Object, ByVal RecognitionType As SpeechRecognitionType, ByVal Result As ISpeechRecoResult)
' Log/Report recognized phrase/information
Console.WriteLine("Reached here......")
TextBox1.Text = "Text should change"
End Sub
When i debug the application, flow is not reaching the RecoContext_Recognition method. The input file is a wav file with 16 bits per sample, 30 sec long conversation.
I am using the code mentioned in this link :
http://msdn.microsoft.com/en-us/library/ee431813(v=vs.85).aspx
How can i check for the issue ? I had read somewhere that dictation needs training to be given to Speech Recognition engine, if its required in my case too then how can i do that? Also in the link it is mentioned that we need to specify the length of the input file in order to do
this, am not sure how to do this as well. Help needed.
The sample code is missing a few steps that need to be addressed.
1) Inproc recognizers need to bind an engine before they will do any recognitions at all;
2) The inproc recognizer needs to be set active before it will start processing audio.
You should also consider adding handlers for other events, in particular SPEI_START_SR_STREAM, SPEI_SOUND_START, SPEI_SOUND_END, and SPEI_PHRASE_START to verify that the SR engine is processing audio at all and that it's trying to do some recognition.