HI - and thanks for the reply If you want to chat about this - call me at 510 889 1453 I Posted this reply a bit early - and have found a small glitch I have modified the code a bit - here is the most recent version using a directcast . . . The other version hung on the response statement - forever - and the network is basically empty during the hang The reply is a 1-4 byte string. ---> Glitch - the directcast returns the entire web page string - I found the following as an alternate suggestion - it works - but seems to time out on each request (my test file has 2 records, and the total time is about 12 seconds) - but if I un-comment the test1 string I get sub second response to a browser window. My DevEnv is VisualStudio2008 WebRequestString = "http://ws.geonames.org/gtopo30?lat=" & lineArray(LatPosition) & "&lng=" & lineArray(LonPosition) 'Dim test1 As String = "http://www.geonames.org/gtopo30?lat=33.7669399&lng=-116.4134417" Dim Request As HttpWebRequest Dim Response As HttpWebResponse Dim reader As StreamReader Dim sbSource As StringBuilder Try Request = DirectCast(WebRequest.Create(WebRequestString), HttpWebRequest) Request.KeepAlive = False response = DirectCast(Request.GetResponse(), HttpWebResponse) If Request.HaveResponse = True AndAlso Not (response Is Nothing) Then ' Get the response stream reader = New StreamReader(response.GetResponseStream()) ' Read it into a StringBuilder sbSource = New StringBuilder(reader.ReadToEnd()) End If Catch wex As WebException ' This exception will be raised if the server didn't return 200 - OK ' Try to retrieve more information about the network error If Not wex.Response Is Nothing Then Dim errorResponse As HttpWebResponse = Nothing Try errorResponse = DirectCast(wex.Response, HttpWebResponse) MsgBox("The server returned '{0}' with the status code {1} ({2:d})." & errorResponse.StatusDescription & " , " & errorResponse.StatusCode & " , " & errorResponse.StatusCode) Finally If Not errorResponse Is Nothing Then errorResponse.Close() End Try End If Finally If Not Response Is Nothing Then Response.Close() End Try
rfrank5356
Posts
-
Problems getting httpWebRequest to work -
Problems getting httpWebRequest to workHI - and Help ! I have a small working app that formats a request to Google Maps, an retireves the data. I copied the code to access a USGS site - and the string works but the code hangs. Here is the code Sub GetElevationData() 'This is based upon GoogleMaps access code 'WebRequestString = "http://ws.geonames.org/gtopo30?lat=" & lineArray(LatPosition) & "&lng=" & lineArray(LonPosition) ' this is the eventual string . . . but I am using the following as a test - I can ctrl click and the link comes up ok with a 2 digit elevation. Dim test1 As String = "http://ws.geonames.org/gtopo30?lat=33.7669399&lng=-116.4134417" ' documentation is available at http://www.geonames.org" Dim Request As HttpWebRequest = CType(WebRequest.Create(test1), HttpWebRequest) 'Request.MaximumAutomaticRedirections = 5 Tried these (and lots other options - but no joy) 'Request.AllowAutoRedirect = True Dim Response As HttpWebResponse = CType(Request.GetResponse(), HttpWebResponse) 'This seems to time out Dim str As Stream = Response.GetResponseStream() Dim inBuf(10000) As Byte Dim bytesToRead As Integer = CInt(inBuf.Length) Dim bytesRead As Integer = 0 While bytesToRead > 0 Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead) If n = 0 Then Exit While End If bytesRead += n bytesToRead -= n End While MsgBox("bytesread " & bytesRead) 'says 4 'inBuf now has the elevation 'bytesRead has the string length Dim elevationvalue As String = inBuf.ToString MsgBox(elevationvalue) ' says system byte [] 'lineArray(elevationPosition) = elevationvalue Response.GetResponseStream().Dispose() End Sub Thanks Bob
-
USB Com emulator Port MisbehavesHi - I have a VB.Net app that controls several devices - including a servo on a USB/Com port using a VCP - I am adding another device with another USB/Comport VCP driver and my vb.et program will not send the write buffer contents to the port, but does not throw an error but hangs on the next read. I have tested the interface and device (a USBI/O24R board) using hyperterminal and the device and ports work fine. Lots of time searching for a similar problem - no joy - so here are a few questions. Is there a limit on how many USB/Serial (virtual COm Port) emulators in a system. Is there a problem with high com munbers (I started at 17) - but I should point out that I move the USB/Serial port to com2 with the same results. Is there a problem with the USBI/O24R driver ? I have had a few emails with the chip supplier but no help yet except try getting to a lower com port - no results. Below is an extract of my test code . . . I added the GetSerialPortNames to see what was happening - POrtmon shows tthe name of the port and the open/close and a single write of "0A" but none of the data string. No change when the VCP was forced to Com2 Thanks for the help Bob __________________________________________ Public SwitchCommName As String = "COM2" Public SwitchCommSpeed As Integer = 9600 Public SwitchCommParity As System.IO.Ports.Parity = IO.Ports.Parity.None Public SwitchCommDataBits As Integer = 8 Public SwitchCommStopBits As System.IO.Ports.StopBits = IO.Ports.StopBits.One Public SwitchComDataOut As String Public SwitchCommFlowControl As System.IO.Ports.Handshake = IO.Ports.Handshake.None Dim SwitchCom As SerialPort = My.Computer.Ports.OpenSerialPort(SwitchCommName, SwitchCommSpeed, IO.Ports.Parity.None, SwitchCommDataBits, IO.Ports.StopBits.One) Public SwitchCommdataOut As String Public SwitchCommDataIn As String Public Switch_WordOK As Boolean = False Sub InitializeRemoteSwitch() Call GetSerialPortNames() MsgBox("OK") SwitchCom.DiscardInBuffer() 'ID device First SwitchCommdataOut = "?TTTTTTT" '& vbCrLf SwitchCom.WriteLine(SwitchComDataOut) Try SwitchCommDataIn = SwitchCom.ReadLine() MsgBox(SwitchCommDataIn) Catch ex As Exception End Try 'Set I/02 as Input (switch), I/04 as output (Red) and I/06 as Output (Green) 'Default is input 'Values = 2 , 8 and 32 so output total is 40 Dim S
-
Need example for read/write bmpThanks very much - I've downloaded the sdk, looked at some of the references - still working - Is there a short vb code snippet I can grab that will allow me to get a single image and start rummaging - I have gone through a zillion (well - maybe a million) pages and no simple thing that I can grab - Once I have a start - I can usually make progress . . . Thanks Again !! Best Bob
-
Need example for read/write bmpHi I need to build an app that does the following - I am processing about 1000 10MP files each week . . . Read a jpg, inflate to bmp in memory search the bmp row by row for a selected color - when found copy and display a 300x400 pixel snippet, determine the min/max x-y bounds of the homogenous color and save for later exclusion processing, create a new bmp structure with this data, allow a user to enter a string to append to the original file name (or OCR the pixels contained in the bounded area), then save the new image, and continue searching frombeyond the bounded area. I think I need an api to read the jpg data into a bmp table - then do some straightforward line scanning, some calculations for determining the bounds of the extract area, then an api to an ocr routine, then an api to write the new file. Does anyone have pointers to code snippets that will model any of these components Thanks Bob
-
Remove Quote from Writeline outputHi - I have an app that reads a csv file line by line, parses for two fields, sends a query to a web server, receives four data fields back, and then writes an output line with the new fields followed by the contents of the input line. My problem is that the four fields are bracketed in quotes, and the entire input line is included in a set of quotes, so if I then open the output file with excel, the input line contents are treated as a single cell - not a series of csv fields. I then changed the code to loop through the fields and put commas in the string - but the output line still has quotes at the start and end of the string - so I I wan to use in Excel - I still need to open as a text file an strip out the pesky quotes. What to do ?? Here is the code doing the data assembly ID = ID + 1 WriteOutputLine = ID & "," & response.GeocodedAddresses(i).Alternatives(0).Quality.ToString & "," & HouseNo & "," & Street & "," & City & "," & State & "," & Zip & "," For DataFieldCount = 0 To lineArray.Length - 1 WriteOutputLine = WriteOutputLine & lineArray(DataFieldCount) & "," Next WriteLine(2, WriteOutputLine) Here is a sample input line . . 37.30840674,-122.0333179,-122.029614,37.30833842,1083.826,179,299,WGS 84,SCMAD20070713,Murky Pool,,7/13/2007 21:43,IMG_6212 copy_tag.jpg,IMG_6212 copy.jpg,,,585992.34,4129519.64,10 N,7/13/2007 14:43,,178.7832,100.2,,,,Canon Canon EOS DIGITAL REBEL XT Adobe Photoshop Elements 4.0 Windows Here is a sample output line "1,Exact,7360,Fallenleaf Ln,Cupertino,CA,95014,37.30840674,-122.0333179,-122.029614,37.30833842,1083.826,179,299,WGS 84,SCMAD20070713,Murky Pool,,7/13/2007 21:43,IMG_6212copy_tag.jpg,IMG_6212copy.jpg,,,585992.34,4129519.64,10 N,7/13/2007 14:43,,178.7832,100.2,,,,Canon Canon EOS DIGITAL REBEL XT Adobe Photoshop Elements 4.0 Windows," rfrank5356
-
Need Source code analyzerHi Hans Thanks for the reply ! Yes, there are a few products for C++ - but my code is in VB.Net - Any suggestions ? Thanks bob
-
Need Source code analyzerHi - I have a moderately complex app built in vb.net in Visual Studio that controls a servo system, a camera, a gps and a file system - I need a documentation tool that will let me see a call tree - and a where used list (data in a subroutine and where defined) - and I would like it not to cost an arm and leg - Suggestions ?
-
Problem with Readline - I broke it !Thanks for the response - I have looked pretty carefully but nothing is obvious - the problem seems to be that PortMon sees the string comming in - but the readline(ServoDataIn) statement in the vb code either gets an incomplete transfer or garbage - I am not certain which . . . this is all very slow stuff and not much data is moving . . .
-
Problem with Readline - I broke it !Hi - I have a small development app that (used to) talk to a servo on a com port, and get a status reply. I have somehow really fixed it (I tried to simplify the code) - but the symptoms are maddening, and I do not see what I did other than move a readline from a subroutine to be inline with the code. Here is what I have Public ServoCommName As String = "COM4" Public ServoCommSpeed As Integer = 9600 Public ServoCommdataOut As String Public ServoCommDataIn As String Public ServoCommParity As System.IO.Ports.Parity Public ServoCommDataBits As Integer Public ServoCommStopBits As System.IO.Ports.StopBits Public Com2 As SerialPort = My.Computer.Ports.OpenSerialPort(ServoCommName, ServoCommSpeed, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One) Then the subroutine . . . Public Sub GetServoStatus() ' Sends a status request and then gets Status from the Servo serial port. ServoCommdataOut = cstCameraServoAddress & "&R" Call SendSerialData() 'This will return the Firmware Version 'just in case wait 500 ms ' I have tried all sorts of delays . . . it worked before with 500 Call DelayTimer(DelayTime) ServoCommDataIn = Com2.ReadLine() MsgBox("End Read" & DelayTime & ServoCommDataIn) outLabel = "Read Servo" outMessage = ServoCommDataIn Call WriteToLog(outLabel, outMessage) ServoStatusBoxOut = "Ready" ServoStatusBox = ServoStatusBoxOut End Sub Here is the portmonitor recording for this part of the code . . . The response comes in on line 52 and portmon says it is fine ! 32 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_BAUD_RATE slabser1 SUCCESS Rate: 9600 33 7:18:29 AM CameraControlV1 IOCTL_SERIAL_CLR_RTS slabser1 SUCCESS 34 7:18:29 AM CameraControlV1 IOCTL_SERIAL_CLR_DTR slabser1 SUCCESS 35 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_LINE_CONTROL slabser1 SUCCESS StopBits: 1 Parity: NONE WordLength: 8 36 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_CHAR slabser1 SUCCESS EOF:1a ERR:0 BRK:0 EVT:1a XON:11 XOFF:13 37 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_HANDFLOW slabser1 SUCCESS Shake:0 Replace:0 XonLimit:128 XoffLimit:128 38 7:18:29 AM CameraControlV1 IOCTL_SERIAL_CLR_RTS slabser1 SUCCESS 39 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_TIMEOUTS slabser1 SUCCESS RI:-1 RM:-1 RC:-2 WM:0 WC
-
Using a DLL in VS with VB - Help ! [modified]I have a canon sdk – my VB program has the following code (which I extracted from a Canon sample program and which works in their really complex example) . . . I refuse to tell you how long it took me to get here :) Public Declare Function EdsGetPropertySize Lib "EDSDK" ( _ ByVal inRef As IntPtr, _ ByVal inPropertyID As Integer, _ ByVal inParam As Integer, _ ByRef outDataType As EdsDataType, _ ByRef outSize As Integer) As Integer This does not generate an error in Visual Studio = However the following set of statements (on the next line) Public Declare Function EdsGetPropertyDesc Lib "EDSDK" ( _ ByVal inRef As IntPtr, _ ByVal inPropertyID As Integer, _ ByRef outPropertyDesc As EdsPropertyDesc) As Integer Generates an error EdsPropertyDesc is not defined I suspect this is VS operator error (ME) – I must not understand how to import all of the methods from a DLL – and the msdn library is not helpful When I try to put in a new Declare function - the autocomplete has a few of the methods from within "EDSDK" but not all . . .I have tried to open the edsdk.dll from the object browser - I can see the file, but when I select add the file appears i the lower select list but when I hit the OK button I get an error "The following Components could not be browsed" -- modified at 14:00 Tuesday 30th January, 2007
-
Port ScannerWell thanks ! I am using a Canon EOS with a Canon SDK, and an Allmotion servo control and a Garmin GPS I can use Using com1 As IO.Ports.SerialPort = My.Computer.Ports.OpenSerialPort("COM4") on error return com1.WriteLine(CommDataOut) End Using to get to the servo (it is still a bit flaky) - I am using CP2100 usb-to-uart bridge software and it shows in the device window as COM4 Next task is to scan the ports to get the location of the (serial usb) devices - I wil target the Garmin GPS 60 first Any Ideas ?? Thanks !! bob
-
This must be too simple - but . . .Well thanks ! It took me a while but I managed to suss out the following . . . and the values are correct - I wound up declaring\f every6thing as double I am using a Canon EOS with a Canon SDK, and an Allmotion servo control and a Garmin GPS Next is to scan the com ports to get the location of the serial usb devices Any Ideas ?? Thanks Again !! bob Private Sub CalculateAngularVelocity(ByVal GPSSpeedIn As Double, ByVal AltitudeAGLIn As Double) 'This uses a HP9100 encoder, 500 counts per motor revolution, 303.366 counts per degree 'Formula W (Rads per sec) = V (Ft Per sec) / R (Ft) ConvertSuccessful = Double.TryParse(AltitudeAGL.Text, AltitudeAGLIn) If Not GPSPresent Then ConvertSuccessful = Double.TryParse(GPS_GroundSpeed.Text, GPSSpeedIn) End If GroundVelocity = GPSSpeedIn * FeetPerNauticalMile / SecondsPerHour AngularVelocity = GroundVelocity / AltitudeAGLIn MsgBox("GS " & GroundVelocity) MsgBox("alt " & AltitudeAGLIn) Dim AngularVelocityDegrees As Double AngularVelocityDegrees = Math.PI * 2 * AngularVelocity MsgBox("Angular Velocity" & AngularVelocityDegrees) CountRate = AngularVelocity * CountsPerRad MsgBox("CountRate" & CountRate) End Sub
-
This must be too simple - but . . .HI I am building a camera control app - I am getting Error 3 Value of type 'System.Windows.Forms.TextBox' cannot be converted to 'Decimal'. C:\Documents and Settings\Compaq_Owner\My Documents\Visual Studio 2005\Projects\CameraControlV1\CameraControlV1\Form1.vb 288 25 CameraControlV1 I have a field defined on a form as a textbox (no mask)but I could change it to a masked box Private Sub AltitudeAGL_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AltitudeAGL.TextChanged AltitudeAGLIn = AltitudeAGL End Sub I want to move this into the following variable and use for calculations . . . Dim AltitudeAGLIn As Decimal = 0 So I can use it in the following where all variables are dim'ed as Decimal Private Sub CalculateAngularVelocity(ByVal GPSSpeedIn As Integer, ByVal AltitudeAGLIn As Integer) 'This uses a HP9100 encoder, 500 counts per motor revolution, 303.366 counts per degree 'Formula W (Rads per sec) = V (Ft Per sec) / R (Ft) Dim CountsPerRad As Decimal = 17379.79D GroundVelocity = GPSSpeedIn * FeetPerNauticalMile * SecondsPerHour AngularVelocity = Decimal.Divide(GroundVelocity, AltitudeAGLIn) CountRate = AngularVelocity * CountsPerRad End Sub As I said - this must be simple - but the Visual Studio help system is not helping !