What port is my USB device connected to? - usb

The command :
ioreg -p IOUSB -l -b | grep -E "#|PortNum|USB Serial Number"
gives :
o USB 2.0 Hub#14200000 <class AppleUSBDevice, id 0x1000311c8, registered, matched, active, busy 0 (1 ms), retain 14>
{
"sessionID" = 28933243797551
"iManufacturer" = 0
"bNumConfigurations" = 1
"idProduct" = 1025
"bcdDevice" = 256
"Bus Power Available" = 500
"USB Address" = 9
"bMaxPacketSize0" = 64
"iProduct" = 1
"iSerialNumber" = 0
"bDeviceClass" = 9
"Built-In" = No
"locationID" = 337641472
"bDeviceSubClass" = 0
"bcdUSB" = 512
"USB Product Name" = "USB 2.0 Hub"
"PortNum" = 2
"non-removable" = "no"
"IOCFPlugInTypes" = {"9dc7b780-9ec0-11d4-a54f-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"}
"bDeviceProtocol" = 1
"IOUserClientClass" = "IOUSBDeviceUserClientV2"
"IOPowerManagement" = {"DevicePowerState"=0,"CurrentPowerState"=3,"CapabilityFlags"=65536,"MaxPowerState"=4,"DriverPowerState"=3}
"Device Speed" = 2
"idVendor" = 6720
"IOGeneralInterest" = "IOCommand is not serializable"
"IOClassNameOverride" = "IOUSBDevice"
}
This is the exact device. I am however having trouble figuring out the port name in the "tty" system.

Related

thermal printer stalls when printing image

I have two Bluetooth thermal printers as well as an integrated device.
One of the printers doesn't support QR codes via GS ( k .. 49, so I'm printing by loading a file.bmp into a Bitmap kotlin class and then sending as image via GS v 0.
The problem I'm facing is that when I print the QR image the other printer stalls mid-image.
I must restart the printer for it to work properly, otherwise it'll print garbage.
The source file has the following characteristics:
82x82 pixels
2.9x2.9 cm print size (needs to be 3 cm)
24 bits per pixel
2 colors
It's loaded into a kotlin Bitmap as such:
var bfo = BitmapFactory.Options()
bfo.outHeight = 20
bfo.outWidth = 20
bfo.inJustDecodeBounds = false
val fRawBmp = File(qrCodeRawFilePath)
val rawBmp = BitmapFactory.decodeFile(fRawBmp.absolutePath, bfo)
.outHeight and .outWidth don't seem to have any effect on dimensions (probably used for screen rendering?). The rawBmp object has the following characteristics:
82x82 px
total Bytes: 26896
bytes per row: 328
bytes per px: 4
Since the width is too small it must be scaled with:
if(inBmp.width < 264) {
val startTime = System.nanoTime()
qrBmp = Bitmap.createScaledBitmap(inBmp, 264, 264, true)
val endTime = System.nanoTime()
val duration = endTime - startTime
wasScaled = true
}
This changes the characteristics to
264x264px
total bytes 278784
bytes per row 1056
bytes per px 4
Since the width is a multiple of 8 it doesn't need to be padded.
I then setup the GS v 0 header:
val bytesPerLine = ceil((widthInPx.toFloat() / 8f).toDouble()).toInt()
val m = 0 // 0-3
val xH = bytesPerLine / 256
val xL = bytesPerLine - xH * 256
val yH = heightInPx / 256
val yL = heightInPx - yH * 256
val imageBytes = ByteArray(8 + bytesPerLine * heightInPx)
System.arraycopy(byteArrayOf(0x1D, 0x76, 0x30, m.toByte(), xL.toByte(), xH.toByte(), yL.toByte(), yH.toByte()), 0, imageBytes, 0, 8)
I must have 1 bit per pixel or the image will be distorted. I achieve it with this (adapted from ESCPOS-ThermalPrinter):
var i = 8
for (posY in 0 until heightInPx) {
var jj = 0
while (jj < widthInPx) {
val stringBinary = StringBuilder()
for (k in 0..7) {
val posX = jj + k
if (posX < widthInPx) {
val color: Int = qrBmp.getPixel(posX, posY)
val r = color shr 16 and 0xff
val g = color shr 8 and 0xff
val b = color and 0xff
if (r > 160 && g > 160 && b > 160) {
stringBinary.append("0")
} else {
stringBinary.append("1")
}
} else {
stringBinary.append("0")
}
}
imageBytes[i++] = stringBinary.toString().toInt(2).toByte()
jj += 8
}
}
The final parameters are:
m: 0
xL: 33 bytes
xH: 0 bytes
yL: 8 dots
yH: 1 dots
k: 8712
data: 8720 bytes (8+k)
I then send it fo the OutputStream of the Bluetooth socket and the printer chokes on the image.
I'm testing with multiple devices with different Android versions, ABIs, Bluetooth versions and architectures - occasionally it'll print on one device or another, must it mostly fails.
If using some demo apps from the net, the printer does print images, so I assume I'm doing something wrong.
Perhaps the image is too big for the buffer?
Edit 1
On a simple test using text1 + image + text2, it'll print text1 and image if i flush the stream; but won't print text2, i.e.:
bt.outStream!!.write(byteArrayOf(0x1B, 0x74, 0x02)) // ESC t codepage PC437 USA Standard Europe
bt.outStream?.write("text1\n".toByteArray(Charsets.ISO_8859_1))
br.outStream?.flush()
var bfo = BitmapFactory.Options()
bfo.inJustDecodeBounds = false
val fRawBmp = File(path2file)
val rawBmp = BitmapFactory.decodeFile(fRawBmp.absolutePath, bfo)
bt.outStream?.write(bmp2Bytes(rawBmp))
bt.outStream?.flush()
bt.outStream?.write("text2\n\n\n".toByteArray(Charsets.ISO_8859_1))
bt.outStream?.flush()
bt.outStream?.close()
bt.inStream?.close()
bt.socket?.close()
The QR code is readable but i must still restart the printer. So I must be overflowing something...
Turns out the problem wasn't in the printer buffer, missing ESC/POS command or data size.
I must wait before closing the Bluetooth socket otherwise there may be unsent data.
So,
Thread.sleep(400) // 200ms is enough for _most_ devices I tested
bt.outStream?.write("text2\n\n\n".toByteArray(Charsets.ISO_8859_1))
bt.outStream?.flush()
bt.outStream?.close()
bt.inStream?.close()
bt.socket?.close()

Why is setting the expiry time ineffective in Redis

Now i use redispipeline to set key to redis ,and set key timeout.After running codes and timeout,and the keys are still in redis?It seemed doesn't work.Is there sth wrong with my code.
X[1] is dict,such as dict["a"]=b dict["c"]=d
redis_pool = redis.ConnectionPool(host = redis_ip, port = redis_port, decode_responses = False)
redis_connection = redis.StrictRedis(connection_pool = redis_pool)
redis_pipeline = redis_connection.pipeline(transaction = False)
sync_count = 0
for x in iterator:
key = suffix + x[0]
#value = str(x['tagid'])+"\t"+x['tag_name']
value = x[1]
redis_pipeline.hmset(key, value)
redis_pipeline.expire(key,60)
sync_count += 1
if (sync_count % 100 == 0):
result = redis_pipeline.execute()
print (result)
time.sleep(0.001)
break
if sync_count == 10000:
break
redis_pipeline.execute()

Sk Physics Joint not working properly

I am creating a game and for my character his legs and torso have separate animations so they are separate nodes with separate physics bodies. I am having a lot of trouble linking the torso and the legs together however, linking them is not the problem, keeping them linked is. While moving around sometimes the hero's torso slides off of the legs. Kind of funny but not practical lol. Here is my physics coding
enum BodyType:UInt32 {
case bullet1 = 2
case enemy1 = 4
case enemy2 = 16
case enemy3 = 32
case desertForegroundCase = 64
case tank11 = 128
case tank12 = 256
case tank13 = 512
case tank21 = 1024
case tank22 = 2048
case tank23 = 4056
case tank31 = 8112
case tank32 = 16224
case tank33 = 32448
case cliff1 = 64856
case cliff2 = 129212
case soldierT = 258424
case soldierL = 516848
}
func CreateScene (){
desertBackground.position = CGPoint(x: frame.size.width / 2, y:
frame.size.height / 2)
desertBackground.size = CGSize (width: 1136, height: 640)
desertBackground.zPosition = -5
desertForegroundImage.position = CGPointMake(568, 100)
desertForegroundImage.zPosition = -1
let desertForeground = SKSpriteNode(texture:
desertForegroundTexture, size:CGSize(width: 1136, height: 200))
desertForeground.position = CGPointMake(568, 100)
let desertForegroundBody = SKPhysicsBody(texture:
desertForegroundTexture, size: CGSize(width: 1136, height: 200))
desertForegroundBody.dynamic = false
desertForegroundBody.affectedByGravity = false
desertForegroundBody.allowsRotation = false
desertForegroundBody.categoryBitMask =
BodyType.deserForegroundcase.rawValue
desertForegroundBody.contactTestBitMask = BodyType.enemy1.rawValue
| BodyType.enemy2.rawValue | BodyType.enemy3.rawValue |
BodyType.soldierL.rawValue | BodyType.soldierT.rawValue
desertForeground.physicsBody = desertForegroundBody
desertForeground.zPosition = -1
self.addChild(desertForegroundImage)
self.addChild(desertForeground)
self.addChild(desert gully)
}
func CreateHero (){
soldierLegs.position = CGPoint(x: 405 , y: 139)
soldierLegs.zPosition = 1
soldierLegs.anchorPoint.x = 0.6
soldierLegs.anchorPoint.y = 0.7
let soldierLegsBody:SKPhysicsBody = SKPhysicsBody(rectangleOfSize:
soldierLegs.size)
soldierLegsBody.dynamic = true
soldierLegsBody.affectedByGravity = true
soldierLegsBody.allowsRotation = false
//body.restitution = 0.4
soldierLegsBody.categoryBitMask = BodyType.soldierL.rawValue
soldierLegsBody.contactTestBitMask = BodyType.enemy1.rawValue |
BodyType.enemy2.rawValue | BodyType.enemy3.rawValue |
BodyType.desertForegroundCase.rawValue
soldierLegs.physicsBody = soldierLegsBody
soldierTorso.position = soldierLegs.position
soldierTorso.zPosition = 2
soldierTorso.anchorPoint.x = 0.25
soldierTorso.anchorPoint.y = 0.1
let soldierTorsoBody:SKPhysicsBody = SKPhysicsBody(rectangleOfSize:
soldierTorso.size)
soldierTorsoBody.dynamic = true
soldierTorsoBody.affectedByGravity = true
soldierTorsoBody.allowsRotation = false
soldierTorsoBody.categoryBitMask = BodyType.soldierT.rawValue
soldierTorsoBody.contactTestBitMask = BodyType.enemy1.rawValue |
BodyType.enemy2.rawValue | BodyType.enemy3.rawValue |
BodyType.desertForegroundCase.rawValue
soldierTorso.physicsBody = soldierTorsoBody
let joint =
SKPhysicsJointFixed.jointWithBodyA(soldierLegs.physicsBody!, bodyB:
soldierTorso.physicsBody!, anchor: soldierLegs.position)
self.addChild(soldierTorso)
self.addChild(soldierLegs)
self.physicsWorld.addJoint(joint)
}
That's about how far he will slide off. Is there a way to just code one physics body with 2 separate nodes? or am i just missing a little code? Any help is help, thank you.

Passing variables in python from radio buttons

I want to set values depends on the selected radio button and to use that values in other function.
Whatever i try, i always get the same answer
NameError: global name 'tX' is not defined #
import maya.cmds as cmds
from functools import partial
winID='MSDKID'
def init(*args):
print tX
print tY
print tZ
print rX
print rY
print rZ
return
def prozor():
if cmds.window(winID, exists = True):
cmds.deleteUI(winID);
cmds.window()
cmds.columnLayout( adjustableColumn=True, rowSpacing=10 )
cmds.button(label = "Init")
cmds.button(label = "MirrorSDK",command=init)
cmds.setParent( '..' )
cmds.setParent( '..' )
cmds.frameLayout( label='Position' )
cmds.columnLayout()
collection2 = cmds.radioCollection()
RButton0 = cmds.radioButton( label='Behavior' )
RButton1 = cmds.radioButton( label='Orientation' )
cmds.button(l='Apply', command = partial(script,RButton0,RButton1,))
cmds.setParent( '..' )
cmds.setParent( '..' )
print script(RButton0,RButton1)
cmds.showWindow()
def script(RButton0,RButton1,*_cb_val):
X = 0
rb0 = cmds.radioButton(RButton0, q = True, sl = True)
rb1 = cmds.radioButton(RButton1,q = True, sl = True)
if (rb0 == True):
tX = -1
tY = -1
tZ = -1
rX = 1
rY = 1
rZ = 1
if (rb1 == True):
tX = -1
tY = 1
tZ = 1
rX = 1
rY = -1
rZ = -1
return tX,tY,tZ,rX,rY,rZ
prozor()
The variables you are defining in script() are local to that function. The other functions don't see them.
If you need multiple UI elements to share data, you'll probably need to create a class to let them share variables. Some reference here and here

Sphinx doesn't create index files in Windows

search.conf file:
source app_main
{
type = pgsql
sql_host = localhost
sql_user = blizzard_moz455_1_3
sql_pass = adminpwd
sql_db = blizzard_moz455_1_3
sql_port = 5432
sql_query = \
SELECT "id", "header", "date", "is_paid", "text", 10 as content_type\
FROM app_main
sql_query_info = SELECT * FROM "app_main" WHERE "id" = $id
sql_attr_uint = content_type
sql_attr_timestamp = date
}
index app_main
{
source = app_main
path = D:/blizzard/Projects/Python/Web/moz455/app/sphinx
docinfo = extern
morphology = stem_enru
min_word_len = 2
charset_type = utf-8
html_strip = 1
html_remove_elements = script
min_prefix_len = 0
min_infix_len = 3
enable_star = 1
}
indexer
{
mem_limit = 32M
}
searchd
{
listen = 127.0.0.1:3312
log = searchd.log
query_log = query.log
read_timeout = 5
max_children = 30
pid_file = searchd.pid
max_matches = 1000
}
Output of the command "indexer --config sphinx.conf --all":
using config file 'sphinx.conf'...
indexing index 'app_main'...
collected 1 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 1 docs, 143 bytes
total 0.065 sec, 2172 bytes/sec, 15.19 docs/sec
total 2 reads, 0.000 sec, 2.5 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 1.2 kb/call avg, 0.0 msec/call avg
I.e. no errors. But index files are not created.
"D:/blizzard/Projects/Python/Web/moz455/app/sphinx" isn't really a folder - last part ("sphinx") is a prefix to files. They were created in "app" folder: sphinx.spa, ..., sphinx.sps