Get serial num of removable usb harddrive in vb6 - vb6

Am trying to get the manufacturer serial number (not volume number) of usb external harddrives or disk?
[EDIT]
i don't know or have any code yet on how to do this. the previous method i tried only returned the volume serial number

You can use WMI to retrieve this information. Hard drive serial numbers are in Win32_PhysicalMedia. I'm not going to take the time to write the code here; if you have any experience querying WMI in VB 6, you should be able to do it without much trouble. Otherwise, search for sample code online. You won't find much of anything specifically about hard drive serial numbers, but you'll find lots of WMI examples.
Be weary of the fact that you won't always get the serial number in the format you're expecting. For example, comments to this article indicate you might get something like:
Serial No. : 4a3532544e464137202020202020202020202020
in which case, you will have to decode the serial number:
By converting to hexdecimal bytes, we get the following (0x20 is blank character and is trimmed out):
0x4a, 0x35, 0x32, 0x54, 0x4e, 0x46, 0x41, 0x37
Swapping the odd and even bytes gets the following:
0x35, 0x4a, 0x54, 0x32, 0x46, 0x4e, 0x37, 0x41
The above ASCII codes are equal to the serial number string:
"5JT2FN7A"
I'm also not positive that all external/removable hard drives provide this information. Your mileage may vary, but the suggested method does work fine on internal hard drives.
Alternatively, it appears that you can do this using low-level Windows APIs like DeviceIOControl. You'll need to add declarations for the necessary functions to a module in your VB 6 app. This article on Code Project should help get you started; the code is written in native C++ and it's geared for consumption by .NET languages like C#, but I see no difficulty in adapting the code to VB 6.

Related

Multidrop Bus addressing

Currently I am reading the MDB_interface_specification( (https://namanow.org/wp-content/uploads/Multi-Drop-Bus-and-Internal-Communication-Protocol.pdf) Version 4. 3(July 2019). In Kapitel 2.3 page 34 they are talking about the Peripheral Address and I don't undrstand how the Address scheme has been built . One prototy of the address scheme look like this: 00101xxxB ( this can be 28H for example ). They upper five bits are used for addressing and the lower 3 bit are the command. If i considered this statement wih my example then the address ist 5 and the Command is 0. I am a little bit confuse can someone please explain me that?
OK. First, read this:
Then, we have value 0x00 as command to Energy Management System (huh, i never saw this kind of MBD device in the wild). MDB datasheet doesn't contain any references to this device yet, but seems it's just POLL command, device must respond to POLL with last status changes (if any) or just ACK with x100 - it's not mistake, it's 0x00 with 9th bit set. Don't read this datasheet unless you want to lose your mind. I am already read this awesome shit and put it (mostly) to hardware implementation see github repo with complete solution
Cheers.

ttyusb/uart sends 'USB' during transfer

I am using Go for a project and am transmitting data to an embedded device via the serial port (ttyusb). During fast and "large" transfers I've noticed that the transmitted data did not match the values I'd wanted to send.
I've tried various available libraries, in the end they all read and write using syscalls. So I've attached a Logic Analyzer to see what's going on.
Then I noticed that the data mismatch in the output had a clear pattern: Instead of sending my data the serial port would interleave my data with the following values:
0x55, 0x53, 0x42, 0x53, 0x70, 0x02
Followed by zeros (0x00). In total 22 Bytes. The total number of bytes transmitted via the serial line did match the number of bytes I wanted to write > so essentially my data was masked with these 22 Byte-Blocks. The weird thing is that I can translate those bytes to ASCII
0x55, 0x53, 0x42, 0x53, 0x70 = "USBSp"
Now my Question is: Can't I send arbitrary data (HEX values) over the serial port or are there some control characters that I should be aware of that would make the serial port send out Identity information or the like?
[EDIT]: Additional Information:
Host is MacOS running Go v1.10; tried with go.bug.st/serial.v1 and github.com/tarm/serial, various communication settings (bitrate etc.)
Target is nRF52840 preview development kit, using Nordic nRF5 SDK v12.3.0_d7731ad (not the newest, I know, but the only one supporting other boards too). Using app_uart_x API
you have to configure the serial port. the settings for both devices for baud rate, start/stop bits, ... have to match. then there are libraries in go like https://github.com/jacobsa/go-serial that enable standard serial port communication with that you can also use any hex values.
i can not say why the USBSp is sent because you did not post any code and gave no information what libraries you use. very likely this is not generated by the kernel module and instead by higher layer software because the kernel module used is usb-serial and USBSp does not appear in the source code :
https://elixir.bootlin.com/linux/v4.0/source/drivers/usb/serial/usb-serial.c
also not in kernel module ftdi-sio ( if you use ftdi chip )
https://elixir.bootlin.com/linux/v4.0/source/drivers/usb/serial/ftdi_sio.c
and also not in https://elixir.bootlin.com/linux/v3.3/source/drivers/usb/core/urb.c

Windows USB HID Report Length

I am developing a USB HID device using an STMicro microcontroller. I started with STMicro's HID example which works fine. I am using C++ on Windows 7 64-bit for the PC side. I have an application that works with my device. There is one thing I can't figure out, however.
The example firmware only allowed sending and receiving 2 bytes at a time, which is determined by a HIDP_CAPS.OutputReportByteLength and InputReportByteLength. I would like to send more data than this at once, but I can't figure out how to increase the report lengths. I successfully changed the endpoint wMaxPacketSize, the VID and PID, and a few other things, but I can't figure out how Windows is calculating the in and out report lengths. There doesn't seem to be any fields in my report or device descriptions that indicate this length, but I can't imagine where else it might be coming from.
Can anyone tell me how Windows determines the HIDP_CAPS.OutputReportByteLength and HIDP_CAPS.InputReportByteLength?
How can I increase these lengths?
I figured it out. I thought I would post here in case anyone else needs to know. I'm not entirely sure I really understand it all, so if I made a mistake, someone please correct me.
I had to change the report description in my firmware. I had several usages. Windows gets the report description and figures out which usage requires the longest length and uses that length. On one of my input reports I made the following changes (the input report is just an array of bytes in firmware):
0x27, 0xFF, 0xFF, 0xFF, 0xFF, //Logical maximum is 4 bytes long, and has a value of 0xFFFFFFFF
0x95, 0x01, //There is one report
0x75, 0x20, //There are 32 bits per report
I did something similar for the output, but there is no report number field (0x95).
Windows now tells me I can send and receive 5 bytes, which I believe means the end point plus report number times report size.

pcsc-sharp Mifare Authentication

I'm using the pcsc-sharp library to communicate with an ACR122U Reader an read/write information to MIFARE Classic 1k cards.
After getting familiar with the library and the APDU concept I'm able to use the cards UID as identifier in my applications.
Now I am in need of setting my own ID's to the card. Therefore I read some manuals regarding NXP's MIFARE (like MF1S70YYX_V1) and also got some information about ISO 7816-4.
I'm aware of the need to do authentication before accessing the cards memory to perform read/write operations and I know the standard Key value.
I downloaded the pcsc-sharp examples from GitHub and ran the Mifare1kTest example. I works but card.LoadKey in Line 36 fails. The response values of the Apdu command in LoadKey is SW1=99 SW2=0, which I cannot find in any documentation. Commenting out the "throw new Exception" section makes the example work.
My question now is, which values are the correct ones to pass to Card.LoadKey, respectively which are the correct values to use for parameters in the Apdu Command. What is meant with "keynumber" (Sectornumber - Sector/Block Combination)? Is the LoadKey call necessary, if the example works?
Your question is broad, but these should work for you. Code is explained with comments
var loadKeySuccessful = card.LoadKey(
KeyStructure.VolatileMemory,
0x00, // first key slot
new byte[] {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} // key
);

COM port terminal program

I have developed an embedded application which requests status information from a device down a communications channel. My customer requires that these will be sent with a specific time period, so what I am looking for is a PC terminal application which can send a text string command repeatedly at a set interval over a period of time. I currently use a serial device tester which can immediately send back a set string when something is sent to it, but I need to control the time period and number of repititions.
Are there any applications (for Windows) out there which can acheive this?
Docklight / Docklight Scripting
For testing applications communication over the serial port it is the best tool for the job.
It listens for user defined sequences on serial port and can then trigger a transmission with parameters derived from the input message or function in a script.
I wrote a C++ program to test a embedded serial application and it was +/- 1000 lines of code. I was able to replace this with about 20 lines of vb script in Docklight Scripting.
Docklight is definitely worth the money.
I would tend to implement a short python script to do this (it can be compiled to a standalone executable with py2exe if that's what you need). Install python and pyserial. Then use a script like this:
#!/usr/bin/python
import time
import serial
# Interval in seconds
interval = 2.5
# Number of times to send
repetitions = 10
# Simple Command string
command_string = "Hello World"
# Or if it's a binary-type command:
command_bytes = [0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64]
command_string = "".join([chr(c) for c in command_bytes])
# Open the serial port - most of these settings have
# defaults in case you want to be lazy
ser = serial.Serial(
port=0, # This is COM1, use 1 for COM2 etc
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
xonxoff=0,
rtscts=0,
timeout=0)
# Loop 'repetitions' times
for i in range(repetitions):
# Send the string
ser.write(command_string)
# Go to sleep for "interval" seconds
time.sleep(interval)
However, if you want a more conventional Windows application, then you can probably do it with Docklight, possibly combined with Docklight Scripting (available from the same site).
The serial terminal emulation application Tera Term, has a scripting language which will be capable of setting up timed loops.
http://ttssh2.sourceforge.jp/
http://en.wikipedia.org/wiki/Tera_Term
I use RealTerm. You can write scripts for it and have it send that file repeatedly. You can add delays between characters or delays between lines. It's a little buggy sometimes, but it's great for the price (free).
http://realterm.sourceforge.net/
Although answered already, i use http://www.hw-group.com/products/hercules/index_de.html . Their app is free and in the serial tab, i can send and receive data from rs232. works like a charm.
ScriptCommunicator (open-source, cross-platform) is the right tool for you. It has many features and a very useful script interface.
You can use the built in windows task scheduler to run a simple batch script that writes texts to a the com port some think like
echo "Hell there" > COM1:
But I've not done this is in yers so my syntax is rusty. Otherwise you could use a simple 'termulator' program that supports scripting - again I've not done this in a decade I think.
GModLab - cross-platform, scriptable (JS) terminal: https://github.com/tardigrade888/gmodlab
You can write scripts that do anything.

Resources