|
In my company we use an instrument that connects to our laptops via a USB-to-Serial bridge (the instrument only communications via RS232). Now, I have figured out how to communication with the instrument from a laptop, however I am trying to figure out how to communicate with it from a PPC (most of the employees have the iPaq but some have newer PDAs that run Windows Mobile).
Below is the sample code of how my laptop software communications with the instrument. Any idea on how to do this from the PPC would be greatly appreciated.
Dim SerialPort As SerialPort = New SerialPort(COMPort, 9600, Parity.None, 8, StopBits.One)
Dim ACK(1) As Byte
Public ENQ() As Byte = {&H5}
Public BEGIN() As Byte = {&H54}
Public DataBuffer(4096) As Byte
Dim SerialPortOK As Boolean = False
SerialPort.Open()
SerialPort.Write(ENQ, 0, ENQ.Length)
Threading.Thread.Sleep(2000)
If SerialPort.BytesToRead Then
SerialPort.Read(ACK, 0, 1)
If ACK(0) = &H6 Then
SerialPortOK = True
Else
MsgBox("The instrument returned an unexpected result. Please check the instrument and try again.", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Invalid Response")
SerialPort.Close()
End If
Else
MsgBox("The instrument did not respond. Please check that it is connected and set to download mode.", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "No Response")
SerialPort.Close()
End If
If SerialPortOK Then
Download = New clsDownloadInstrument(FolderName, txtDownload.Text.Trim, InstrumentNumber, SerialPort)
Me.Enabled = False
Download.BeginDownload()
End If
|
|
|
|
|
I can probably help you on this, do the ppc's? have a serial port, and which version of Visual Studio are using?
Phil
Software Developer
http://www.yorkshirehumberit.co.uk
|
|
|
|
|
I'm using visual studio 2008. The PDA has a USB (Not serial) port on the bottom. I'm connecting the USB cable for the PDA to a ATEN USB-to-Serial Bridge, which is then connected to the instrument.
|
|
|
|
|
does the pda recognise the USB Bridge as a serial port in its device manager?
Phil
Software Developer
http://www.yorkshirehumberit.co.uk
|
|
|
|
|
Hi all,
I wrote a COM add-in for Excel with VB2008 Express. While the main "Connect" class (holding all the Extensibility stuff) seems to start in the way it's supposed to, a second class seems to produce a runtime error while starting. I say "seems" because to first impression it works, but during startup it's "loadBehaviour" value in the registry is reset from 3 to 2, pointing out a runtime error during startup.
Obviously there's no way to debug the addin while Excel is starting it up... so what would be a way (the best way ) to find out which runtime error might cause that effect?
Thanks for any hints,
Michael
|
|
|
|
|
Logging[^] is one of my major development tools.
|
|
|
|
|
Thank you, Luc.
I do log the commands in my AddIn to a file, using a TextWriterTraceListener. Unfortunately that doesn't lead me anywhere - I call the AddIn class and get proper log results. But when I look at the respective Resistry values I see they have been reset (again and again).
The runtime error seems to occur during the loading process, and I guess it's an Excel activity to reset Registry values if it can't properly load an AddIn. I need to find out which statement or method in my AddIn makes the loading process fail... so I'd need a way to trace Excel's addin-loading activity, which seems to be even beyond workbook's VBA modules (guessing that from the fact that add-ins are present even without workbooks).
Do you have an idea how I could do that?
|
|
|
|
|
Did you put logging statements at the beginning of your suspected methods? All you have to do is log something like "Got to <some class:somemethod="">" at the top of your suspected methods. You don't have to put this on every method, just the top level ones.
Have you tried launching Excel (without your addin enabled), attaching the debugger to the Excel process, then loading the addin?
|
|
|
|
|
Thanks for your time, Dave.
I've added Trace statements to the relevant (likely errorous) class, starting in the New constructor. The lines are written, so it's got to be something else. But what do you mean with "...attaching the debugger to the Excel process..."? How would I do that / which debugger to use?
Looking forward,
Mick
|
|
|
|
|
Under the Tools menu in Visual Studio, Attach to Process... Oh, you may want to set a breakpoint in the constuctor of your suspect class.
|
|
|
|
|
Thank you for the hint. Unfortunately it seems like the Express version doesn't have any 'Attach to process' options - but I've just found it in SharpDevelop (which I had rarely used by now), so that I'll try to get forward with it and follow your approach.
|
|
|
|
|
Michael Schäuble wrote: the Express version doesn't have any 'Attach to process'
correct[^].
Without other debug facilities, you'd have to add more log statements to your code. Make sure you catch and log exceptions as much as possible.
|
|
|
|
|
Whoops. I didn't see you were using Express in your first post... Sorry!
|
|
|
|
|
Hi All,
I have a userform (BinSheetForm) which I bind to a datasource as per the code below.
Private Sub BinSheetForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
BsCountIdLabel.Text = iCountId.ToString
Dim Conn As New SqlConnection(CntString)
conn.Open()
adapter = New SqlDataAdapter("select * from zz_ST_Binsheets", Conn)
adapter.FillSchema(dtset, SchemaType.Source, "zz_ST_Binsheets")
adapter.Fill(dtset, "zz_ST_Binsheets")
Conn.Close()
bind.DataSource = dtset
bind.DataMember = "zz_ST_Binsheets"
End Sub
On this userform I have a datagridview that I fill with the follwing code.
Private Sub FillBinDataGrid()
With Me.BsDataGridView
.DataSource = bind
.EditMode = DataGridViewEditMode.EditOnEnter
End With
End Sub
Up to this point it works fine, but now I want to do 2 more things.
First:
The database table zz_ST_Binsheets contains columns "iCountId" and "iBinNr". I have a label on the from that contains the value of "iCountId" and a textbox where the user can enter a value for "iBinNr". The user will then press a button and the datagridview must only be filled with the selection where "iCountId" = the label value and "iBinNr" = the textbox value.
Second:
I want the changes that the user make to be saved back to the database. The changes would include editing current data, adding new rows and deleting current rows.
I am using VS2005.
Thanks in advance.
|
|
|
|
|
To remove the need to go back and refilter the data to the selected iCountId and iBinNr values, you can use client side filter capabilities of the BindingSource . The binding source has a Filter property which acts like an additional where clause of the query, but does not requery the database.
Set the BindingSource.Filter to "Where iCountId=" & textBoxiCountId.text & " AND iBinNr= " & textBoxiBinNr.text
You can then Edit the data and save changes as you would do normally. When you are finished with the filter, it can be removed by BindingSouce.RemoveFilter()
[obviously change the names of the controls to match yours]
|
|
|
|
|
Thanks, that filter property had the desired effect. It is so simple if you how
I have one more problem which I think wil also have a simple solution.
I add a comboboxcolumn to the datagridview as follows:
Dim InvCode As New DataGridViewComboBoxColumn
and then add the details and further down
BsDataGridView.Columns.Insert(5, InvCode)
The problem is that it now adds a new column every time I run the query for a different bin nr.
|
|
|
|
|
At your form level, declare a reference to the InvCode object (without new);
Dim InvCode As DataGridViewComboBoxColumn
In your code you run at present, test this InvCode object for being Nothing and if it is create it and add it to the DGV, if it is not nothing, then you have already created it, so do not create it again.
if isnothing(InvCode) then
InvCode = new DataGridViewComboBoxColumn()
BsDataGRidView.Columns.Insert(5,InvCode)
else
end if
[Edit: wrong syntax initially]
Dave
Don't forget to rate messages!Find Me On: Web| Facebook| Twitter| LinkedInWaving? dave.m.auld[at]googlewave.com
modified on Tuesday, June 29, 2010 9:42 AM
|
|
|
|
|
That worked like a charm, thanks.
|
|
|
|
|
|
Thanks for the link - I will have a look.
|
|
|
|
|
I am having some problems getting a printer driver to work in Visual Basic.
I am stuck at not being able to get a printer handle from the printer dll.
This is what I got thus far;
Static dll_loaded As Boolean
If Not dll_loaded Then
Dim dll_handle = LoadLibrary("ZBRPrinter.dll")
If dll_handle = 0 Then
MsgBox("LoadLibrary failed")
Return
Else
dll_loaded = True
MsgBox("LoadLibrary success!")
End If
End If
Dim pName As StringBuilder = New StringBuilder("Zebra P330i USB Card Printer")
Dim hPrinter As IntPtr = 2
Dim printerType = 330
Dim err As Integer = 0
Dim ret = ZBRGetHandle(hPrinter, pName, printerType, err)
If err = 61 Then
MsgBox("Unable to open handle to Zebra printer driver")
End If
I am using the following pinvoke sig:
DllImport("ZBRPrinter.dll", SetLastError:=True, CharSet:=CharSet.Auto)> Public Shared Function ZBRGetHandle(ByRef hPrinter As IntPtr, ByVal pName As StringBuilder, ByRef printerType As Integer, ByRef err As Integer) As IntPtr
End Function
I am getting the following data returned to me as I run this code;
hprinter gets changed from 2 (test number) to 0
pname is the stringbuilder (also tried it as a string)
printertype is 330
err is 61
It seems that I am getting "through" to the dll but I am unable to get a proper printer handle.
This is what I got in Zebra SDK:
HMODULE hModule = LoadLibrary(_T("ZBRGPMF.dll"));
if (hModule)
{
form1.StatusBox->Text = "The DLL has been successfully loaded.";
}
else
{
return FALSE;
}
zsdkGetHandle = (ZBRGetHandle)GetProcAddress(hModule, "ZBRGetHandle");
HANDLE hPrinter = NULL;
INT printerType = NULL;
INT err = 0,
ret = 0;
ret = getHandle(&hPrinter, "Zebra P330i USB Card Printer", &printerType, &err);
ret = getPrinterStatus(&err);
And by running that example I do get a handle returned (its 0x000000) and the thing works.
This is the typedef I got with the SDK:
typedef INT (CALLBACK *ZBRGetHandle)(LPHANDLE hPrinter, LPSTR pName, INT* printerType, LPINT err);
I am (quite obviously) new to adapting the code from C# to VB, I have managed to make several projects work (win32 API based) but I hit a wall on this one, please help if you can, any suggestions are most welcome, thanks in advance!
|
|
|
|
|
do you use VB6 oder .net ??
try the following pinvoke sig:
<br />
declare function ZBRGetHandle lib "ZBRPrinter.dll" (ByRef hPrinter As IntPtr, <System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)> byval szBuffer as String, byval printerType As IntPtr, ByRef err As Integer) As IntPtr<br />
does complile but i don't know if this would solve your problem
|
|
|
|
|
.Net, Studio 2008
By studying the SDK example, I deduce that the entries for printer type and name are irrelevant as they havent used those as well (value = 0).
I am getting the error code back as I should (61 or 63, error getting data from the printer) so it would seem that the pinvoke works at least partially, what I am still not getting is the proper handle for the printer itself.
|
|
|
|
|
Let us suppose that I am having problems marshalling a null terminated char array to the function I wish to call (GetHandle function as stated in the previous post(s)).
I guess I should "reserve" a specific size memory (malloc or something), fill it with chars taken from the string, make sure its null terminated and then pass this memory by reference to the dll. Additionally I think the pointer points only to the first element of the char array, dont know how this will reflect on the problem at hand.
I have no idea how to achieve the above mentioned Any help? sample code?
|
|
|
|
|
did you try my example code ???
i am marshalling the string into a LPSTR in the example.
greetz
|
|
|
|
|